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

Databound treeview and selectedItem cast to Treeviewitem

Closed Thread
 
Thread Tools Display Modes
Old 11-13-2006   #1 (permalink)
cheesetarmac
Guest


 

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
Old 11-14-2006   #2 (permalink)
cheesetarmac
Guest


 

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

Old 11-14-2006   #3 (permalink)
cheesetarmac
Guest


 

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

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databound animation Joao Paulo Duque Vieira Avalon 4 04-13-2008 11:28 AM
TreeView, TreeViewItem knallkopf66 Avalon 1 08-16-2007 08:24 PM
How to get the Parent of a TreeViewItem in a treeview when using HierchicalDataTemplate ? Pon Avalon 1 04-05-2007 03:16 AM
Drag and Drop Treeview Items between 2 Treeview ProjectGKR Avalon 3 03-14-2006 07:29 AM
Select hidden treeviewitem in databound treeview RyanLeeSchneider Avalon 0 01-31-2006 06:59 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