TreeView node right-clicked is not the "selected" node...
-
Why is it that when I right click on a tree node and my context menu pops up, the item that is returned by the treeView1.SelectedNode property is not the item that was right-clicked on, but whatever tree node happend to be selected before the right click? i.e. Folders _________ |FolderA| <-- Currently selected tree node --------- FolderB FolderC <-- Right click here treeView1.SelectedNode returns FolderA, not FolderC, even thought the selected node highlighting box temporarily moved to FolderC. Scratching my head... Thanks, Rick
-
Why is it that when I right click on a tree node and my context menu pops up, the item that is returned by the treeView1.SelectedNode property is not the item that was right-clicked on, but whatever tree node happend to be selected before the right click? i.e. Folders _________ |FolderA| <-- Currently selected tree node --------- FolderB FolderC <-- Right click here treeView1.SelectedNode returns FolderA, not FolderC, even thought the selected node highlighting box temporarily moved to FolderC. Scratching my head... Thanks, Rick
Thats just the way the TreeView works. Crappy answer, but if you look at the behavior in Windows Explorer it is the same. I believe the justification is that selecting the node is so you can tell which node was right-clicked on. Right clicking should not select an item; you are merely requesting a menu to popup. James
-
Why is it that when I right click on a tree node and my context menu pops up, the item that is returned by the treeView1.SelectedNode property is not the item that was right-clicked on, but whatever tree node happend to be selected before the right click? i.e. Folders _________ |FolderA| <-- Currently selected tree node --------- FolderB FolderC <-- Right click here treeView1.SelectedNode returns FolderA, not FolderC, even thought the selected node highlighting box temporarily moved to FolderC. Scratching my head... Thanks, Rick
As James said, that is by design. The way to work around the design is like so:
treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);
Call that before you pop-up the context menu -- David Wengier Sonork ID: 100.14177 - Ch00k
-
Thats just the way the TreeView works. Crappy answer, but if you look at the behavior in Windows Explorer it is the same. I believe the justification is that selecting the node is so you can tell which node was right-clicked on. Right clicking should not select an item; you are merely requesting a menu to popup. James
I have to disagree, at least w/respect to how Windows Explorer works. If I left click Folder "A" in explorer to select it, then right click on folder "B" and select "properties" I get a property page for folder "B", not folder "A". This is the behaviour on Windows 2000. If I were programming with pure Win32, I would just do a hit-test on the item under the mouse cursor, but I can't find an analog in C#.NET. Thanks, Rick
-
As James said, that is by design. The way to work around the design is like so:
treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);
Call that before you pop-up the context menu -- David Wengier Sonork ID: 100.14177 - Ch00k
-
I have to disagree, at least w/respect to how Windows Explorer works. If I left click Folder "A" in explorer to select it, then right click on folder "B" and select "properties" I get a property page for folder "B", not folder "A". This is the behaviour on Windows 2000. If I were programming with pure Win32, I would just do a hit-test on the item under the mouse cursor, but I can't find an analog in C#.NET. Thanks, Rick
rhoward wrote: If I left click Folder "A" in explorer to select it, then right click on folder "B" and select "properties" I get a property page for folder "B", not folder "A". Correct, but when you close the property page the folder "B" *isn't* selected, folder "A" is. Sorry I didn't make that clear in my posting. James
-
rhoward wrote: If I left click Folder "A" in explorer to select it, then right click on folder "B" and select "properties" I get a property page for folder "B", not folder "A". Correct, but when you close the property page the folder "B" *isn't* selected, folder "A" is. Sorry I didn't make that clear in my posting. James