[win32api] Editable List View Report?

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
First, you have to create the List view control with the LVS_EDITLABELS style, as shown here:
http://msdn.microsoft.com/en-us/library/bb774736%28VS.85%29.aspx

Then, when you want to edit the label, you send the LVM_EDITLABEL message to the focused label.
http://msdn.microsoft.com/en-us/library/bb774898%28v=VS.85%29.aspx

Be sure to handle the LVN_ENDLABELEDIT message in the parent.
http://msdn.microsoft.com/en-us/library/bb774814%28v=VS.85%29.aspx
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?
Do you want something like LVS_EX_FULLROWSELECT extended style ? By default it selects multiple items, but only on first column.

You can get edit control handle by sending LVM_GETEDITCONTROL message while processing LVN_BEGINLABELEDIT. You can customize the text by sending appropiate messages to the edit control.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774919%28v=vs.85%29.aspx

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 -.-
Topic archived. No new replies allowed.