Dump a CListCtrl
This snippet dumps the content of a CListCtrl in to a file.
It also gets the number of columns in the list. <blockquote> <p>int GetColumnsCount( CListCtrl * list )
{
if( list != NULL )
{
const CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl*) list->GetDlgItem(0);
if( pHeaderCtrl != NULL ) {
return pHeaderCtrl->GetItemCount() ;
}
}
return 0;
} </p> <p>void DumpList( FILE * file, CListCtrl * list )
{
if( file == NULL && list == NULL )
{
return ;
} </p> <p> CString csText ;
int columnCount = GetColumnsCount( list );
for( int iRows = 0 ; iRows < list->GetItemCount() ; iRows++ )
{
for( int iCols = 0 ; iCols < columnCount ; iCols++ )
{
csText = list->GetItemText( iRows, iCols ) ;
fprintf_s( file, "%s,", csText );
}
fprintf_s( file, "\n" );
}
}</p></blockquote>
Leave a comment