MFC之ListCtrl相关操作(转)
原文:https://blog.csdn.net/myruo/article/details/84326769
基础操作:
1、插入列
CString strLoad;
RECT rectList;
GetDlgItem( IDC_LIST )->GetClientRect( &rectList );
int nLength = int( rectList.right - rectList.left );
int nColumn = 2;
int nWidth = ( nColumn > 0 ) ? nLength / nColumn : nLength; /*平均分割*/
m_list1.DeleteAllItems();
strLoad = _T( "name" );
m_list1.InsertColumn( 0, strLoad, LVCFMT_LEFT, nWidth * 1 );
strLoad = _T( "age" );
m_list1.InsertColumn( 1, strLoad, LVCFMT_LEFT, nWidth * 1 );
2、插入数据(行)
int nCount = m_list1.GetItemCount();
m_list1.InsertItem( nCount, _T("zhao") );
m_list1.SetItemText( nCount, 1, _T("18"));
3、删除所有列
for( int i = 0; i < 2; i++ )
{
m_list1.DeleteColumn( 0 ); //动态删除
}
4、判断是否有列
if (m_list1.GetColumnWidth(0))
{
return false;
}