How can I select a node in a treeview
-
Hi fellows. I have a treeview(populated) and I would like to select a single node I have this code:
case WM_NOTIFY: { TV_ITEM tempTvItem; char cTemp[256]=""; unsigned int uiVal = 0; LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(treeViewHwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); //itoa((int)nodeSelected, cText, 10); tempTvItem.mask = TVIF_TEXT|TVIF_HANDLE; tempTvItem.hItem = nodeSelected; tempTvItem.pszText = cTemp; tempTvItem.cchTextMax = 256; SendMessage(treeViewHwnd, TVM_GETITEM, 0, (LPARAM)&tempTvItem); MessageBox(NULL, tempTvItem.pszText, "", MB_OK); ...
My problem is that the select part. The node isn`t selected and in the MessageBox nothing is shown. What`s the problem? I want when I select the node it remais highlighted and selected. -
Hi fellows. I have a treeview(populated) and I would like to select a single node I have this code:
case WM_NOTIFY: { TV_ITEM tempTvItem; char cTemp[256]=""; unsigned int uiVal = 0; LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(treeViewHwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); //itoa((int)nodeSelected, cText, 10); tempTvItem.mask = TVIF_TEXT|TVIF_HANDLE; tempTvItem.hItem = nodeSelected; tempTvItem.pszText = cTemp; tempTvItem.cchTextMax = 256; SendMessage(treeViewHwnd, TVM_GETITEM, 0, (LPARAM)&tempTvItem); MessageBox(NULL, tempTvItem.pszText, "", MB_OK); ...
My problem is that the select part. The node isn`t selected and in the MessageBox nothing is shown. What`s the problem? I want when I select the node it remais highlighted and selected.Where did you get IDC_TREE1 from?? If you are using a CTreeView view, why aren't you using GetTreeCtrl()->SelectItem(...);? AliR. Visual C++ MVP
-
Where did you get IDC_TREE1 from?? If you are using a CTreeView view, why aren't you using GetTreeCtrl()->SelectItem(...);? AliR. Visual C++ MVP
I`m not using CTreeView, I`m creating the treeview with CreateWindowEx function. and in the HMENU part I include the IDC_TREE1 like the ID of the window..... Like this:
treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL);
-- modified at 17:19 Wednesday 19th July, 2006 -
I`m not using CTreeView, I`m creating the treeview with CreateWindowEx function. and in the HMENU part I include the IDC_TREE1 like the ID of the window..... Like this:
treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL);
-- modified at 17:19 Wednesday 19th July, 2006In that case try this nodeSelected = (HTREEITEM)SendMessage(treeViewHwnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); AliR. Visual C++ MVP
-
In that case try this nodeSelected = (HTREEITEM)SendMessage(treeViewHwnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); AliR. Visual C++ MVP
Ali unhappilly, this code doesn`t work too.... I`m almost changing to TreeView_SelectItem....