CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    96

    Finding & Selecting 2nd column in a list control

    HI all,
    How do I find text in 2nd column in my list control and then select it. I have a list control with 2 columns. Code and description. Now, I have a edit box where the user enters the description which is to be searched in the list control.

    The CListCtrl::FindItem searches only the strings in the first column. Also how do I select this found row.

    Thx & Rgds,
    -Suri




  2. #2
    Join Date
    Jun 1999
    Location
    Saint leger sur Roanne - FRANCE
    Posts
    4

    Re: Finding & Selecting 2nd column in a list control



    That will be work :


    #define EQUALS ==
    #define NOT_EQUALS !=


    /*****************************************************************************/
    void CMyListView::SelectItem( int item )
    {
    LV_ITEM lvi ;
    CListCtrl& ListCtrl = GetListCtrl();
    /*------------------------------- CODE FUNCTION -----------------------------*/
    lvi.mask = LVIF_STATE ;
    lvi.state = LVIS_FOCUSED | LVIS_SELECTED ;
    lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED ;
    lvi.iItem = item;
    ListCtrl.SetItem( &lvi );
    ListCtrl.EnsureVisible( item, FALSE );
    } // End of SelectItem( int item )
    /*****************************************************************************/



    /*****************************************************************************/
    void CMyListView::SearchAndSelect( CString SearchString, int Column )
    {
    CListCtrl& ListCtrl = GetListCtrl();
    int ItemNumber
    /*------------------------------- CODE FUNCTION -----------------------------*/
    ItemNumber = ListCtrl.GetNextItem( -1, LVNI_ALL ) ;
    while ( ItemNumber NOT_EQUALS -1 )
    {
    if ( SearchString EQUALS ListCtrl.GetItemText( ItemNumber, Column ) )
    {
    SelectItem( ItemNumber );
    ItemNumber = - 1 ;
    }
    else
    {
    ItemNumber = ListCtrl.GetNextItem( ItemNumber, LVNI_ALL ) ;
    }
    }
    } // End of SearchAndSelect
    /*****************************************************************************/








    Hoping that help

    Fred



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured