I am trying to use a Dynamic Data Application and having issues with customizing a query. Everything scaffolds wonderfully, however, I want to be able color code the main Parent table when a Child Objects Property is a certain value. Normally I would just iterate over the data using LINQ however, all the information I've researched always filters and color codes items in the grid based on the Parent level data. Any ideas on how to do this on Child Data?
In the ItemDataBound event of the child control, if the condition is met, you can walk up the control hierarchy recursively until you reach the row/item of the parent grid. Once you get to the row/item, you can set the color to whatever you need.
Related
I have a treeview that displays a few nodes, say 5 or so. When the final node is selected, I want to display records belonging to that final node (linked via a foreign key) inside of a listbox.
So the structure would be
Treeview Listbox
-1 -Object belonging to 5
--2 -Object belonging to 5
---3
----4
-----5
My question is if such a comperation between these two controls is even possible and if I'm going about it the smartest way.
I can't find anything about it (getting actual data from the last selected node in the treeview is already pretty hard on how to find a how to). Any tips in the right direction would be very appreciated.
It is possible to do this exactly the way you're trying to by using attached properties, but it's a bit of a clumsy way of going about it. What you really should be doing is using data binding.
Your TreeView is, presumably, bound to some kind of data structure in your view model (data context), and what class that is should (again, presumably) be able to easily ascertain whether or not a particular given item is the deepest/last one in the tree. So create a property in that class and bind the TreeView's SelectedItem to that, so that it gets updated whenever the user selects an item in the Tree. Next, create another property for your ListBox to bind to. When your first property gets set, it either sets this second property to the currently selected item if it's the last in the list, or sets it to null if it isn't.
By doing this you de-couple your logic from your view and you make something that's much easier to debug, test and modify in future.
I have a TreeView which data source is generated in runtime through code to which I don't have access. Its hierarchical data, nodes of tree with 2, 3 or 4 depth levels. I have to make the same structured tree with RadioButtons corresponding to every object in first tree. Is there a way to iterate through every element of TreeView or another method to do my task?
In WPF, we use DataTemplates, or in your case HierarchicalDataTemplates to define how our data should be presented. You already have the data in the first TreeView and that should be accessible from its ItemsSource or Items properties. Therefore, all you need to do is to define another HierarchicalDataTemplate to display the same data object the way that you want it. There is no need to manually iterate through all of the nodes from the original TreeView.
I'm creating some custom object using ContentControl and by adding them to toolbox allowing user to drag/drop them on a page. Now, I'm facing a situation where some of these controls have children. In case it is only one item without children I retrieve each object's id in Tag property, however, for the 2nd category this won't be the case, since I need to store and retrieve a hierarchy set of IDs. After few searches I ran into MSDN forum and it is almost close to what I need to do but I was wondering there are better and more optimized methods of implementation.
Any help will be appreciated.
Thanks.
If an object can have more than one child you use an ItemsControl and not a ContentControl. And an ItemsControl containing ItemsControls is a hierarchy.
I have a silverlight page which has about 5 user controls. Most of the controls are getting the same data from the database which I wanted to save some round trips to DB. I wanted to get the data in the main page and then pass it to the child controls. I tried creating a public property in the controls and setting them from the main page.
What is the best way of doing this?
Thanks.
From your description, it sounds like data binding would be your best approach (MSDN documentation). If you set the main control's DataContext to the object you retrieved from the database, all of the controls in that page will have access to the DataContext as well. This would also allow you to leverage data binding expressions to populate the properties of the UserControls' children.
I am trying to dynamically (i.e. via code) bind a directory to a asp.net Treeview control and once the data is bound and displayed to the user i want to get a list of nodes the select.
I have got the binding and displaying of checkboxes to work fine , but when i query the Treeview1.CheckedNodes it always returns 0. If i do not bind dynamically but created the nodes by hand then it is able to get the selected nodes.
Thanks
My guess is ... since you're dynamically building the whole thing from scratch every page load you're losing the selection.
You need to somehow store info about which checkboxes are checked before the post back (in Viewstate or Session or whatever depending on your needs) and then re-apply those selection to your tree after rebuilding it (on page load or preload if you store it in Viewstate).