Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC CListCtrl FindItem is not working

MFC CListCtrl FindItem is not working

Scheduled Pinned Locked Moved C / C++ / MFC
c++
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D Manivelan
    wrote on last edited by
    #1

    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();
    }
    
    _ L 2 Replies Last reply
    0
    • D D Manivelan

      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();
      }
      
      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      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 ?

      D 1 Reply Last reply
      0
      • D D Manivelan

        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();
        }
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What are the values held in your list control; i.e. is there one that starts with "DFC102"?

        speaking as ...

        1 Reply Last reply
        0
        • _ _Flaviu

          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 ?

          D Offline
          D Offline
          D Manivelan
          wrote on last edited by
          #4

          Yes you are correct. I am searching 2nd column how to solve. please help me.

          _ R 2 Replies Last reply
          0
          • D D Manivelan

            Yes you are correct. I am searching 2nd column how to solve. please help me.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            I suggest you to use this[^] listcontrol, which can search in subitems (columns) too ...

            1 Reply Last reply
            0
            • D D Manivelan

              Yes you are correct. I am searching 2nd column how to solve. please help me.

              R Offline
              R Offline
              Rolf Kristensen
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups