OnInitialDialog
m_list.ModifyStyle(LVS_TYPEMASK, LVS_REPORT);
m_list.InsertColumn(0,_T("第 1 列"), LVCFMT_LEFT, 120);
m_list.InsertColumn(1,_T("第 2 列"), LVCFMT_LEFT, 120);
m_ilLarge.Create(IDB_LARGEDOC, 32, 1, RGB(255,0,255));
m_ilSmall.Create(IDB_SMALLDOC, 16, 1, RGB(255,0,255));
m_list.SetImageList(&m_ilLarge, LVSIL_NORMAL);
m_list.SetImageList(&m_ilSmall, LVSIL_SMALL);
CComboBox *pView;
pView = (CComboBox*)GetDlgItem(IDC_CMB_VIEW);
pView->SetCurSel(3);
void CDemoDlg::OnBnClickedBtnAdd()
{
// TODO: 在此添加控件通知处理程序代码
int nCount = m_list.GetItemCount();
CString strText;
strText.Format(_T("第%d行,第1列"), nCount + 1);
m_list.InsertItem(nCount,strText,0);
strText.Format(_T("第%d行,第2列"), nCount + 1);
m_list.SetItemText(nCount,1,strText);
}
void CDemoDlg::OnBnClickedBtnDelete()
{
// TODO: 在此添加控件通知处理程序代码
int nCount = m_list.GetItemCount();
for(int i=nCount; i>=0; i--)
{
if(m_list.GetItemState(i,LVIS_SELECTED) == LVIS_SELECTED)
m_list.DeleteItem(i);
}
}
void CDemoDlg::OnCbnSelchangeCmbView()
{
// TODO: 在此添加控件通知处理程序代码
DWORD dwStyle;
CComboBox *pView;
pView = (CComboBox*)GetDlgItem(IDC_CMB_VIEW);
switch(pView->GetCurSel())
{
case 0:
dwStyle = LVS_ICON;
break;
case 1:
dwStyle = LVS_SMALLICON;
break;
case 2:
dwStyle = LVS_LIST;
break;
case 3:
dwStyle = LVS_REPORT;
break;
default:
return;
}
m_list.ModifyStyle(LVS_TYPEMASK, dwStyle);
}