suri
June 14th, 1999, 09:26 PM
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
FredericTachet
June 15th, 1999, 02:57 AM
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