Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - TreeView Selection

 
 
Old 01-10-2006   #1 (permalink)
CSkinner


 
 

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 SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
CSkinner


 
 

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 SpecsSystem Spec
Old 01-10-2006   #3 (permalink)
CSkinner


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Need help on treeview VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46