Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TreeViews
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Divers
Thread ID:
00696446
Message ID:
00696463
Vues:
10
Thanks Cathi,

That did the trick. I had been trying to get this to work a coupla weeks ago, and that was before I had known about the TreeView.GetNodeAt() method, which was probably the only piece of the puzzle that I was missing at the time. And, luckily, this is generic enough that I can probably put it in a TreeView baseclass and not have to worry about it again.

But, I'm curious about one thing. It's interesting that the X,Y coordinates of MouseEventArgs is more accurate (if that's the correct description) than the X,Y coordinates of the DragEventArgs. In a similar type of operation with drag/drop (in fact, you may have been the one to post the code for me), I had to take the X,Y coordinates and convert that to a Point and use GetNodeAt(Point) instead of GetNodeAt(X,Y). I had thought it was an extraneous step when I originally was trying this drag/drop code, and so I tried using the X,Y directly, but it would never work. Any ideas why these behave differently? And how to know *when* to use X,Y and *when* you have to do the point conversion???

TIA,
~~Bonnie



>Hi Bonnie,
>
>See if the following code will do what you want. For the TreeView's MouseDown event
>
>
>private void OnTreeViewMouseDown(object
>sender, System.Windows.Forms.MouseEventArgs e)
>        {
>            if (e.Button == MouseButtons.Right)
>            {
>                TreeNode gtn =
>                     (TreeNode)treeView1.GetNodeAt(e.X, e.Y);
>                if (gtn == null)
>                    return;//Then user did not right click on an item
>                treeView1.SelectedNode = gtn;
>            }
>        }
>
>
>>Hey All,
>>
>>I have a TreeView control on a Windows Form. I also have a ContextMenu to pop-up when the user right-clicks on the Tree. No problem, it all works fine ... except for one little thing. If the user right-clicks on a node in the tree other than the one that's selected, when the ContextMenu pops ups, it will appear to them (temporarily) as if that node is selected, when in fact it is not. As soon as an item from the pop-up menu is selected, the highlight goes back to the real selected node (in fact, the TreeView.Selected node never changes, just the highlight).
>>
>>I've been trying to figure out how to change the Selected node to the one that they've right-clicked on, but no luck so far.
>>
>>Any ideas? This is C#, BTW ...
>>
>>TIA,
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform