获取项目文本的索引在MFC CListCtrl [英] Get Index of Item Text in MFC CListCtrl
问题描述
我有一个CString的文本,也是我的CListCtrl的项目文本。例如:
CString m_SearchThisItemText = _T(Banana);
并在我的CListCtrl
m_List.SetItemText(1,1,_T(Banana));
现在我想知道文本的索引。
CListCtrl :: FindItem
无效。它只搜索项目的名称,而不是文本。
我也尝试过
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();
}
}
但它不工作。它停在索引0
任何人都可以帮助我,如何找出文本是哪个项目。
迭代所有项目并在您想要的栏位中搜寻:
int nCol = 1; //在第二列中搜索(像你的问题)
CString m_SearchThisItemText = _T(Banana);
for(int i = 0; i {
CString szText = m_List.GetItemText(i,nCol);
if(szText == m_SearchThisItemText)
{
//找到它 - 做某事
break;
}
}
I've got a CString with a Text that also is an Item Text of my CListCtrl. For example:
CString m_SearchThisItemText = _T("Banana");
And in my CListCtrl
m_List.SetItemText (1, 1, _T ("Banana"));
Now I want to find out, on which Index the Text is.
CListCtrl::FindItem
doesnt work. 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
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;
}
}
这篇关于获取项目文本的索引在MFC CListCtrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!