[英]Get Index of Item Text in MFC CListCtrl
I've got a CString with a Text that also is an Item Text of my CListCtrl. 我有一个CString,它的Text也是CListCtrl的Item Text。 For example:
例如:
CString m_SearchThisItemText = _T("Banana");
And in my CListCtrl 在我的CListCtrl中
m_List.SetItemText (1, 1, _T ("Banana"));
Now I want to find out, on which Index the Text is. 现在,我想找出文本在哪个索引上。
CListCtrl::FindItem
doesnt work. CListCtrl::FindItem
不起作用。 It only searches the name of the Item, not the Text. 它仅搜索项目的名称,而不搜索文本。
I also tried this 我也试过了
for (Index= 0; dlg.GetSearchContentText () == m_List.GetItemText (Index, Spalte); Index++)// HIER IST NOCH EIN FEHLER.
{
if (dlg.GetSearchContentText () == m_List.GetItemText(Index, Spalte))
{
m_List.SetItemState (Zeile, LVIS_SELECTED, LVIS_SELECTED);
m_List.SetFocus();
}
}
But it doesnt work. 但它不起作用。 It stops at Index 0
停在索引0
Can anyone help me, how to find out on which Item the text is. 谁能帮助我,如何确定文本在哪个项目上。
I hope you understand my question. 我希望你能理解我的问题。
Iterate all the items and search in the column you want: 迭代所有项目并在所需的列中搜索:
int nCol = 1; // to search in the second column (like your question)
CString m_SearchThisItemText = _T("Banana");
for (int i = 0; i < m_List.GetItemCount(); ++i)
{
CString szText = m_List.GetItemText(i, nCol);
if (szText == m_SearchThisItemText)
{
// found it - do something
break;
}
}
If you mean that you have a list view with several columns and you want to search in other columns than the first one, then FindItem
won't help you. 如果您的意思是说您有一个包含几列的列表视图,并且想要搜索除第一列之外的其他列,那么
FindItem
将无济于事。 You'll have to explicitly write the find code yourself. 您必须自己明确编写查找代码。 You must iterate over all the rows in the list, and for each column of a row call
GetItemText
and compare what you get with the text you have. 您必须遍历列表中的所有行,并针对行的每一列调用
GetItemText
,并将获得的内容与所拥有的文本进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.