![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | 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 |
| | #2 (permalink) |
| 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 |
| | #3 (permalink) |
| 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 |
| |
| |
![]() |
| 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 |