MFC CListCtrl FindItem is not working
-
I am developing Dialog based application. It has "CListCtrl" list control and one "Editbox". My requirement is when user type in editbox, automatically the entered text should get selected in the list control. For this,when i used "FindItem" , it always return -1 even the entered text available in list control. Here my code
int nPointIndex = 0; LVFINDINFO info; int nIndex; LPCTSTR lpszmyString; info.flags = LVFI\_PARTIAL|LVFI\_STRING; info.psz = \_T("DFC102"); nPointIndex = m\_cListCtrl.FindItem(&info,-1); //It is not working Always return -1 if( nPointIndex != LB\_ERR ) { m\_cListCtrl.EnsureVisible(nPointIndex, FALSE); m\_cListCtrl.SetSelectionMark(nPointIndex); m\_cListCtrl.SetItemState(nPointIndex, LVIS\_SELECTED | LVIS\_FOCUSED, IDC\_TAGBROWSER\_LIST); m\_cListCtrl.RedrawItems(nPointIndex, nPointIndex); m\_cListCtrl.UpdateWindow(); }
-
I am developing Dialog based application. It has "CListCtrl" list control and one "Editbox". My requirement is when user type in editbox, automatically the entered text should get selected in the list control. For this,when i used "FindItem" , it always return -1 even the entered text available in list control. Here my code
int nPointIndex = 0; LVFINDINFO info; int nIndex; LPCTSTR lpszmyString; info.flags = LVFI\_PARTIAL|LVFI\_STRING; info.psz = \_T("DFC102"); nPointIndex = m\_cListCtrl.FindItem(&info,-1); //It is not working Always return -1 if( nPointIndex != LB\_ERR ) { m\_cListCtrl.EnsureVisible(nPointIndex, FALSE); m\_cListCtrl.SetSelectionMark(nPointIndex); m\_cListCtrl.SetItemState(nPointIndex, LVIS\_SELECTED | LVIS\_FOCUSED, IDC\_TAGBROWSER\_LIST); m\_cListCtrl.RedrawItems(nPointIndex, nPointIndex); m\_cListCtrl.UpdateWindow(); }
-
I am developing Dialog based application. It has "CListCtrl" list control and one "Editbox". My requirement is when user type in editbox, automatically the entered text should get selected in the list control. For this,when i used "FindItem" , it always return -1 even the entered text available in list control. Here my code
int nPointIndex = 0; LVFINDINFO info; int nIndex; LPCTSTR lpszmyString; info.flags = LVFI\_PARTIAL|LVFI\_STRING; info.psz = \_T("DFC102"); nPointIndex = m\_cListCtrl.FindItem(&info,-1); //It is not working Always return -1 if( nPointIndex != LB\_ERR ) { m\_cListCtrl.EnsureVisible(nPointIndex, FALSE); m\_cListCtrl.SetSelectionMark(nPointIndex); m\_cListCtrl.SetItemState(nPointIndex, LVIS\_SELECTED | LVIS\_FOCUSED, IDC\_TAGBROWSER\_LIST); m\_cListCtrl.RedrawItems(nPointIndex, nPointIndex); m\_cListCtrl.UpdateWindow(); }
What are the values held in your list control; i.e. is there one that starts with "DFC102"?
-
Here is code that working for me :
LVFINDINFO FindInfo; FindInfo.flags = LVFI\_STRING | LVFI\_PARTIAL; FindInfo.psz = m\_sItem; // sItem = \_T("Something"); int nItem = m\_List.FindItem(&FindInfo);
perhaps you try to search in subitems of the list ?
Yes you are correct. I am searching 2nd column how to solve. please help me.
-
Yes you are correct. I am searching 2nd column how to solve. please help me.
-
Yes you are correct. I am searching 2nd column how to solve. please help me.
You could insert the column you want to search in first, and then change the display order afterwards so it becomes the second column. Or just implement your own search method:
CString token = "hello";
for(int i=0;i