Click to See Complete Forum and Search --> : Selecting a treeview node


C#er
July 19th, 2006, 06:30 PM
Hi fellows.

I have a treeview(populated) and I would like to select a single node I have this code:
this is my treeview, when I creating it?

treeViewHwnd = CreateWindowEx(WS_EX_LEFT, 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);



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.