Get Index of Item Text in MFC CListCtrl(获取 MFC CListCtrl 中项目文本的索引)
问题描述
我有一个带有文本的 CString,它也是我的 CListCtrl 的项目文本.例如:
I've got a CString with a Text that also is an Item Text of my CListCtrl. For example:
CString m_SearchThisItemText = _T("香蕉");
在我的 CListCtrl 中
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不工作.它只搜索项目的名称,而不是文本.
CListCtrl::FindItem
doesnt work. It only searches the name of the Item, not the Text.
我也试过了
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
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 中项目文本的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取 MFC CListCtrl 中项目文本的索引
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
