![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | TreeView Selection How do I make whatever treeitem that happens to be under a right mouse button click the selected item in a TreeView? I've used the myTreeView.InputHitTest( e.GetPosition( myTreeView )) method, but not sure what to do with the IInputElement returned.... Thanks! CS |
My System Specs![]() |
| | #2 (permalink) |
| | Re: TreeView Selection I should also add that I am leveraging the HierarchicalDataTemplate with the TreeView, so I'm not getting TreeViewItem objects ( which has the IsSelected property )... "CSkinner" <cwskinner_no_sppaaam@comcast.net> wrote in message news:ec97FeGAGHA.664@TK2MSFTNGP10.phx.gbl... > How do I make whatever treeitem that happens to be under a right mouse > button click the selected item in a TreeView? I've used the > myTreeView.InputHitTest( e.GetPosition( myTreeView )) method, but not sure > what to do with the IInputElement returned.... > > Thanks! > > CS > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: TreeView Selection Figured it out. I'm posting this as this took me a number of hours to figure out, and I hope this can save some other folks some time. I'd also like to see a MUCH easier way of doing this, so if some smart MS dev can chime in, I'd sure appreciate it! Here's the code. Again, I'm populating a TreeView control using a HierarchicalDataTemplate and wanted to make the Right button down event select the node under the click before raising a context menu: private void OnRightButtonDown( object sender, MouseEventArgs e ) { if( e.MouseDevice.Target is FrameworkElement ) { FrameworkElement element = e.MouseDevice.Target as FrameworkElement; System.Windows.Controls.ContentPresenter pres = element.TemplatedParent as ContentPresenter; if( pres != null ) { TreeViewItem viewItem = pres.TemplatedParent as TreeViewItem; if( viewItem == null ) { viewItem = mProjectTree.ItemContainerGenerator.ContainerFromItem( pres.Content ) as TreeViewItem; } if( viewItem != null ) { viewItem.IsSelected = true; } } } } Cheers, CS "CSkinner" <cwskinner_no_sppaaam@comcast.net> wrote in message news:ec97FeGAGHA.664@TK2MSFTNGP10.phx.gbl... > How do I make whatever treeitem that happens to be under a right mouse > button click the selected item in a TreeView? I've used the > myTreeView.InputHitTest( e.GetPosition( myTreeView )) method, but not sure > what to do with the IInputElement returned.... > > Thanks! > > CS > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Need help on treeview | VB Script | |||