对于winapi的新用户和Listview的使用我无法查看列表视图中不可见的列标题和子项,即可以看到第一列但不显示子项(第1列和第2列)。读者可以告诉我在列表视图中初始化项目的正确方法吗?
列标题不可见 - 我切换了属性设置" No Column Header"对于列表控件而言,它对于显示列标题没有帮助。
HWND listViewHandle = GetDlgItem(formHandle, IDC_CHART_LV); // handle to the list control
//Add column definitions
LVCOLUMN lvc = { 0 };
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
//column 0
lvc.iSubItem = 0;
lvc.cx = 100;
lvc.pszText = TEXT("A");
ListView_InsertColumn(listViewHandle, 0, &lvc);
//column 1
lvc.iSubItem = 1;
lvc.cx = 200;
lvc.pszText = TEXT("B");
ListView_InsertColumn(listViewHandle, 1, &lvc);
//column 2
lvc.iSubItem = 2;
lvc.cx = 200;
lvc.pszText = TEXT("C");
ListView_InsertColumn(listViewHandle, 2, &lvc);
//Setup some dummy items within the listview
LV_ITEM lvItem = { 0 };
//Row 0
lvItem.iItem = 0;
ListView_InsertItem(listViewHandle, &lvItem);
ListView_SetItemText(listViewHandle, 0, 0, TEXT("RS"));
ListView_SetItemText(listViewHandle, 0, 1, TEXT("SS"));
ListView_SetItemText(listViewHandle, 0, 2, TEXT("VS"));
//Row 1
lvItem.iItem = 1;
ListView_InsertItem(listViewHandle, &lvItem);
ListView_SetItemText(listViewHandle, 1, 0, TEXT("SR"));
ListView_SetItemText(listViewHandle, 1, 1, TEXT("GS"));
ListView_SetItemText(listViewHandle, 1, 2, TEXT("SM"));
//Row 2
lvItem.iItem = 2;
ListView_InsertItem(listViewHandle, &lvItem);
ListView_SetItemText(listViewHandle, 2, 0, TEXT("GT"));
ListView_SetItemText(listViewHandle, 2, 1, TEXT("GS"));
ListView_SetItemText(listViewHandle, 2, 2, TEXT("SM"));
SendMessage(listViewHandle, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
ListView_SetItemState(listViewHandle, 1, LVIS_SELECTED, LVIS_SELECTED);