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