取wxListCtrl中某一个cell的值

开始走了弯路,以为是用GetNextItem(),结果却只能第一个column的属性值。
后来搜索官方的wiki,才发现这儿已经提供了解决方案:

wxString MyListCtrl::GetCellContentsString( long row_number, int column )
{
wxListItem row_info;
wxString cell_contents_string;

// Set what row it is (m_itemId is a member of the regular wxListCtrl class)
row_info.m_itemId = row_number;
// Set what column of that row we want to query for information.
row_info.m_col = column;
// Set text mask
row_info.m_mask = wxLIST_MASK_TEXT;

// Get the info and store it in row_info variable.
GetItem( row_info );

// Extract the text out that cell
cell_contents_string = row_info.m_text;

return cell_contents_string;
}

另外一种方法:

bool MyListCtrl::GetCellContentsString( long row_number, int column, wxString& cell_contents_string ) const
{
wxListItem row_info;

// Set what row it is (m_itemId is a member of the regular wxListCtrl class)
row_info.m_itemId = row_number;
// Set what column of that row we want to query for information.
row_info.m_col = column;
// Set text mask
row_info.m_mask = wxLIST_MASK_TEXT;

// Get the info and store it in row_info variable.
if (GetItem( row_info ))
{
// Extract the text out that cell
cell_contents_string = row_info.m_text;
return true;
}

return false;
}

This entry was posted in Program and tagged , , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string PEPtF7 to the field below:

以新浪微博帐号登录