Click to See Complete Forum and Search --> : Node selection problem


C#er
July 18th, 2006, 03:41 PM
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:


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;
}


My code to create the treeview:

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);


Someone can helps? Thanks again