LV & TV strange behavior
-
Hi, I've never used label editing in TreeView & ListView before, so I guess it's a simple question. I used the EditLabels property (LVS/TVS_EDITLABELS) and create the controls. But a strange thing happens. I click on the label to edit and it's ok, but when I press any key (in both the TV and LV) the dialog is dismissed. Also, when I press ENTER (without any char has been pressed), they behave differently: the LV accepts it but the TV close the dialog. What is happening ? What is missing here ? I create a very simple test: a new Win32 App,typical HelloWorld, and include this lines in teste.rc: CONTROL "List1",100,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_EDITLABELS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,7,132,30 CONTROL "Tree1",200,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,7,43,158,24,WS_EX_CLIENTEDGE and include InitCommonControls(); at WinMain and #include "commctrl.h" and put comctl32.lib in the project settings finally I put this on the About function: case WM_INITDIALOG: LVCOLUMN col; col.mask = LVCF_TEXT | LVCF_WIDTH; col.pszText = _T("Col1"); col.cx = 100; ListView_InsertColumn(GetDlgItem(hDlg, 100), 0, &col); LVITEM lv; lv.mask = LVIF_TEXT; lv.pszText = _T("Txt1"); lv.iItem = 0; lv.iSubItem = 0; ListView_InsertItem(GetDlgItem(hDlg, 100), &lv); TVINSERTSTRUCT tv; tv.hInsertAfter = TVI_LAST; tv.item.mask = TVIF_TEXT; tv.hParent = TVI_ROOT; tv.item.pszText = _T("root"); TreeView_InsertItem(GetDlgItem(hDlg, 200), &tv); return TRUE; and that's it. I didn't include the handlers to LVN/TVN_BEGINLABELEDIT and ENDLABELEDIT , but I think this is not the problem. Why the dialog is dismissed when I press any key ? Why the ENTER key is OK with LV but close the dialog in TV ? Did I forget to handle some message or notification here ? Did they act differently in Windows and Dialogs ?
-
Hi, I've never used label editing in TreeView & ListView before, so I guess it's a simple question. I used the EditLabels property (LVS/TVS_EDITLABELS) and create the controls. But a strange thing happens. I click on the label to edit and it's ok, but when I press any key (in both the TV and LV) the dialog is dismissed. Also, when I press ENTER (without any char has been pressed), they behave differently: the LV accepts it but the TV close the dialog. What is happening ? What is missing here ? I create a very simple test: a new Win32 App,typical HelloWorld, and include this lines in teste.rc: CONTROL "List1",100,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_EDITLABELS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,7,7,132,30 CONTROL "Tree1",200,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_EDITLABELS | TVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP,7,43,158,24,WS_EX_CLIENTEDGE and include InitCommonControls(); at WinMain and #include "commctrl.h" and put comctl32.lib in the project settings finally I put this on the About function: case WM_INITDIALOG: LVCOLUMN col; col.mask = LVCF_TEXT | LVCF_WIDTH; col.pszText = _T("Col1"); col.cx = 100; ListView_InsertColumn(GetDlgItem(hDlg, 100), 0, &col); LVITEM lv; lv.mask = LVIF_TEXT; lv.pszText = _T("Txt1"); lv.iItem = 0; lv.iSubItem = 0; ListView_InsertItem(GetDlgItem(hDlg, 100), &lv); TVINSERTSTRUCT tv; tv.hInsertAfter = TVI_LAST; tv.item.mask = TVIF_TEXT; tv.hParent = TVI_ROOT; tv.item.pszText = _T("root"); TreeView_InsertItem(GetDlgItem(hDlg, 200), &tv); return TRUE; and that's it. I didn't include the handlers to LVN/TVN_BEGINLABELEDIT and ENDLABELEDIT , but I think this is not the problem. Why the dialog is dismissed when I press any key ? Why the ENTER key is OK with LV but close the dialog in TV ? Did I forget to handle some message or notification here ? Did they act differently in Windows and Dialogs ?
I think the Edit control of the TreeView (for label editing) on a dialog doesn't handle the ENTER and ESC keys, so they are processed by the system DefDlgProc and directed to DEFPUSHBUTTON. But I think that it's kind of a bug, because the ListView Control does handle the ENTER and ESC keys. I will try to subclass the label edit control of the TreeView and handle the WM_GETDLGCODE message and see if it solves the problem.