Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

TreeView Selection

Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
CSkinner
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


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



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



Closed Thread

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








Vistax64.com 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 2005-2008

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 47 48 49 50