声明
CListCtrl m_userList;
绑定
DDX_Control(pDX, IDC_LIST1, m_userList);
新建
DWORD dwStyle = GetWindowLong(m_userList.m_hWnd, GWL_STYLE);
SetWindowLong(m_userList.m_hWnd, GWL_STYLE, dwStyle | LVS_REPORT);
m_userList.SetExtendedStyle(dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//m_chanList.ModifyStyle(LVS_SORTASCENDING | LVS_SORTDESCENDING,0);
//m_chanList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
char *columnTitle_chan[] = {"通道号","通道状态","呼叫状态","连接号码"};
int columnWidth_chan[] = {60,80,80,80};
LVCOLUMN lvc_chan;
lvc_chan.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
lvc_chan.fmt = LVCFMT_LEFT;
for(int i=0; i<4; i++)
{
lvc_chan.pszText = columnTitle_chan[i];
lvc_chan.iSubItem = i;
lvc_chan.iOrder = i;
lvc_chan.cx = columnWidth_chan[i];
m_userList.InsertColumn(i, &lvc_chan);
}
UpdateData(FALSE);
添加
m_userList.InsertItem(index,strName);
m_userList.SetItemText(index, 1, (strStatus.Compare("No Alarm") && strStatus.Compare("Yellow Alarm"))?"未连接":"已连接");
例如:
m_userList.InsertItem(0,"草地上");
m_userList.SetItemText(0, 1, "未连接");
查找 修改
LVFINDINFO *pFindInfo=new LVFINDINFO;
pFindInfo->flags = LVFI_PARTIAL|LVFI_STRING;
pFindInfo->psz = (LPCTSTR)(chan);
int index = m_chanList.FindItem(pFindInfo);
if(status.GetLength())
m_userList.SetItemText(index, 2, status);
if(number.GetLength())
m_userList.SetItemText(index, 3, number);
UpdateData(FALSE);
delete pFindInfo;
删除
m_userList.DeleteAllItems();