![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 |
| | #2 (permalink) |
| Guest | 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 > |
| | #3 (permalink) |
| Guest | 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 > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help on treeview | Boein | VB Script | 2 | 07-18-2008 02:18 AM |
| TreeView, TreeViewItem | knallkopf66 | Avalon | 1 | 08-16-2007 08:24 PM |
| ListView / TreeView, multiple selection and drag/drop | =?Utf-8?B?RGlyaw==?= | Avalon | 0 | 07-16-2006 02:36 PM |
| Drag and Drop Treeview Items between 2 Treeview | ProjectGKR | Avalon | 3 | 03-14-2006 07:29 AM |
| treeview with lines | Benoist.Demeure | Avalon | 0 | 03-14-2006 07:29 AM |