c++ - 在 MFC CListCtrl 中获取项目文本的索引

标签 c++ mfc clistctrl

我有一个带有文本的 CString,它也是我的 CListCtrl 的一个项目文本。例如:

CString m_SearchThisItemText = _T("香蕉");

在我的 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;    // 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;
    }
}

关于c++ - 在 MFC CListCtrl 中获取项目文本的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19789686/

相关文章:

c++ - 如何在带有 STL vector 的 C++ 中使用类似 matlab 的运算符

c# - COM 接口(interface)从 ROT 中消失

c++ - 如何禁用 CListCtrl 选择选项

c++ - CListCtrl Customdraw 函数中的禁用或灰色行

java - Android 的 Java 和 C++ 之间的队列/取消队列

c++ - 有时会显示透明颜色

c++ - std::hash 特化使用 sfinae?

c++ - PPL 任务 - 在桌面应用程序的 UI 线程中继续

c++ - 在库中拆分实用程序功能以最大化可重用性的最佳方法是什么?

c++ - 如何调整 CListCtrl 列的宽度以适应每列中最长的字符串?