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 - Databound treeview and selectedItem cast to Treeviewitem

 
 
Old 11-13-2006   #1 (permalink)
cheesetarmac


 
 

Databound treeview and selectedItem cast to Treeviewitem

Hi

I've been working on a TreeView that is bound to an ObjectDataProvider and
it's amzaing however, the problem I'm having is that I need to be able to
find out who the PARENT of the currently selected item is so that I can do
some cut copy paste operations on the data that the treeviewitem is bound to
(The data that the ObjectDataProvider displays has no concept of Parent for
the collections).

In the examples it shows that you pretty much do this
public void SelectedItemChanged(object sender, RoutedEventArgs args)
{
TreeViewItem item = (MyTreeView.SelectedItem as TreeViewItem);

}

However, this always returns a null because the MyTreeView.SelectedItem is
actually the object that it's bound to.

So, is it possible to get the actual TreeViewItem rather than the bound item?

Or, is there another way that I can figure out that who the parent of my
item is so that I can operate on the data and have it reflected in the UI?



--
Steve

My System SpecsSystem Spec
Old 11-14-2006   #2 (permalink)
cheesetarmac


 
 

RE: Databound treeview and selectedItem cast to Treeviewitem

Ok, I've been reading the docs a lot more closely and have found that I'd got
the type of the implemented delegate wrong. It should be
RoutedPropertyChangedEventArgs. This still does not solve my issue. To
reproduce what I'm talking about you can modify the SimpleTreeView WPF
example that comes with the SDK.

In Xaml, add an event handler
<TextBlock>
TreeView control created
by databinding with an XMLDataProvider and using a
HierarchicalDataTemplate
</TextBlock>
<TreeView SelectedItemChanged="MySelectedItemChanged"
ItemsSource="{Binding Source={StaticResource myEmployeeData},
XPath=EmployeeInfo}" AllowDrop="True"/>

In .CS file. add the following

private void MySelectedItemChanged(object sender,
RoutedPropertyChangedEventArgs<object> args)
{
TreeViewItem item = (args.Source as TreeViewItem);
if (item != null)
Console.WriteLine(item.ToString());

Console.WriteLine(args.Source.ToString());
}

You'll notice that the cast to TreeViewItem returns null
--
Steve


"cheesetarmac" wrote:

> Hi
>
> I've been working on a TreeView that is bound to an ObjectDataProvider and
> it's amzaing however, the problem I'm having is that I need to be able to
> find out who the PARENT of the currently selected item is so that I can do
> some cut copy paste operations on the data that the treeviewitem is bound to
> (The data that the ObjectDataProvider displays has no concept of Parent for
> the collections).
>
> In the examples it shows that you pretty much do this
> public void SelectedItemChanged(object sender, RoutedEventArgs args)
> {
> TreeViewItem item = (MyTreeView.SelectedItem as TreeViewItem);
>
> }
>
> However, this always returns a null because the MyTreeView.SelectedItem is
> actually the object that it's bound to.
>
> So, is it possible to get the actual TreeViewItem rather than the bound item?
>
> Or, is there another way that I can figure out that who the parent of my
> item is so that I can operate on the data and have it reflected in the UI?
>
>
>
> --
> Steve

My System SpecsSystem Spec
 

Thread Tools



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