Node selection problem
-
Hi fellows In my app I have a treeview with some nodes. I want to select one of them and it will be highlighted. The problem is that I don`t get highlighted neither selected. This is my code to select a node: [Code] case WM_NOTIFY: { LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(hwnd, IDC_TREE1, TVM_GETNEXTITEM, TVGN_CARET, (LPARAM)nodeSelected); if(nodeSelected == NULL)MessageBox(NULL, "", "", MB_OK); TreeView_EnsureVisible(hwnd, nodeSelected); SendDlgItemMessage(hwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); SendDlgItemMessage(hwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_DROPHILITE, 0); } } break; } [/Code] My code to create the treeview: [Code] treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL); [/Code] Someone can helps? Thanks again
-
Hi fellows In my app I have a treeview with some nodes. I want to select one of them and it will be highlighted. The problem is that I don`t get highlighted neither selected. This is my code to select a node: [Code] case WM_NOTIFY: { LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(hwnd, IDC_TREE1, TVM_GETNEXTITEM, TVGN_CARET, (LPARAM)nodeSelected); if(nodeSelected == NULL)MessageBox(NULL, "", "", MB_OK); TreeView_EnsureVisible(hwnd, nodeSelected); SendDlgItemMessage(hwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); SendDlgItemMessage(hwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_DROPHILITE, 0); } } break; } [/Code] My code to create the treeview: [Code] treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL); [/Code] Someone can helps? Thanks again
Not really sure what you are trying to do there. But maybe the tree doesn't have the focus and that's why you are not seeing the selection. Add this TVS_SHOWSELALWAYS to the flags when you are creating the tree to see if that helps. AliR. Visual C++ MVP