Feb 6, 2014 at 9:59am Feb 6, 2014 at 9:59am UTC
I want to make items to be editable in the listview, so I can click/double click on them and edit the values, is this possible in report style list view, or do I have to use other type? I'm creating LV with the code below:
CONTROL "" , IDC_LIST, WC_LISTVIEW, WS_TABSTOP | WS_BORDER | LVS_EDITLABELS | LVS_REPORT, 5, 10, 180, 150
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
case MY_WM_INITDIALOG:
{
INITCOMMONCONTROLSEX icex;
icex.dwICC = ICC_LISTVIEW_CLASSES;
icex.dwSize = sizeof (INITCOMMONCONTROLSEX);
InitCommonControlsEx(&icex);
string *sColumn = new string[COLUMN_MAX];
sColumn[0] = "Col1" ;
sColumn[1] = "Col2" ;
sColumn[2] = "Col3" ;
HWND hTmp = GetDlgItem(hWnd, IDC_LIST);
RECT rc;
GetClientRect(hTmp, &rc);
int rcWidth = rc.right/COLUMN_MAX;
SetWindowPos(hTmp, NULL, rc.left, rc.top, rcWidth*COLUMN_MAX+4, rc.bottom, SWP_NOMOVE | SWP_NOZORDER);
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER | LVCFMT_FIXED_WIDTH;
lvc.cx = rcWidth;
for (int i = 1; i <= COLUMN_MAX; i++)
{
lvc.pszText = (char *)sColumn[i-1].c_str();
ListView_InsertColumn(hTmp, i, &lvc);
}
delete [] sColumn;
break ;
}
and I insert items with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
int InsertToList(HWND hWnd, vector<string> str)
{
int len = str.size();
if (len < 1)
return 0;
LVITEM lvi;
lvi.mask = LVIF_TEXT;
lvi.iItem = ListView_GetItemCount(hWnd);
lvi.iSubItem = 0;
lvi.pszText = (char *)&str[0];
ListView_InsertItem(hWnd, &lvi);
if (len > COLUMN_MAX)
len = COLUMN_MAX;
for (int i = 1; i < len; i++)
{
lvi.pszText = (char *)&str[i];
lvi.iSubItem++;
ListView_SetItem(hWnd, &lvi);
}
return 1;
}
Last edited on Feb 6, 2014 at 10:32am Feb 6, 2014 at 10:32am UTC
Feb 6, 2014 at 12:18pm Feb 6, 2014 at 12:18pm UTC
I have created it using LVS_EDITLABELS style, anyway there are 2 issues:
1. I can edit only the first column, not the second or third or Nth one
2. it is alligned to the left, not to the center while editing
also I normally can't select line/item when clicking in the LV, it just does nothing, how do I allow that?
Feb 10, 2014 at 11:38am Feb 10, 2014 at 11:38am UTC
is there a way to actually allow other columns to be selected? why is it done this way anyway? looks like I will have to subclass the whole listview -.-