How to GetItemData of a Checked Item of a CCheckListBox?
I use MFC VC++ 4.2.
I have been successful in creating CCheckListBox and now I have a problem
with getting the item data.
I need if an item is checked, I want to get that item's text.
Here is when I add the item to the CListBox:
CStringList strFilePathLst;
POSITION pos = strFilePathLst.GetHeadPosition();
int i = 0;
while( pos!= NULL ){
CString sFullPathName = strFilePathLst.GetNext( pos );
if( !sFullPathName.IsEmpty() ){
int iPos = sFullPathName.ReverseFind( '\\' );
CString sFileName;
if( iPos != -1 )
sFileName = sFullPathName.Right( sFullPathName.GetLength() - ( iPos + 1
) );
m_lst_filenames.AddString( sFileName );
m_lst_filenames.SetItemData( i, i );
m_lst_filenames.SetCheck( i, 0 );
}
i++;
}
Here is when I tried to get the checked item data:
CStdioFile file;
if( file.Open( sShpFile, CFile::modeWrite | CFile::modeCreate ) ){
for( int i = 0; i < m_lst_filenames.GetCount(); i++ ){
if( m_lst_filenames.GetCheck( i ) ){
//isikan semua nama file tersebut ke file toadevdb.shp
CString sStrFileName = ( CString )m_lst_filenames.GetItemData( i );
m_strShpFiles.AddTail( m_sScadRelPath + sStrFileName );
file.WriteString( sStrFileName + "\n" );
}
}
file.Close();
}
When I traced it, the sStrFileName variable was EMPTY.
So what was wrong or missing from the above code?
Thank you.