TreeListView with Columns generated and populated by ObservableCollection - wpf

Does anyone known (or even has an example) of a WPF based TreeListView that can generate its colums by databinding to the ObservableCollection of its tree items?
For example the databound model is a tree consisting of Employee instances representing the supervisor hierarchy of a company. Each employee addtionally has a ObservableCollection of Responsibility instances (Properties: ResponsibiltyName, ResponsibleSinceDate). Now I want a separate column for each ResponsibiltyName found in any of the databound Employees and the column value should be populated with the ResponsibleSinceDate. If an Employee does not have a certain Responsibilty the column value shall be left blank.
How would one usually approach such a problem in WPF?

You may want to take a look at the following answer: How do I bind a WPF DataGrid to a variable number of columns?
Here a solution involving a CompositeCollection is suggested: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/a4c5b2de-260c-49d0-b4ff-cca6ee4e8b08/
Here a solution involving a HierarchicalDataTemplate is suggested: http://blogs.msdn.com/karstenj/archive/2005/11/02/488420.aspx
Hope this helps!

Related

WPF: DataGrid with a tree-column in an MVVM Windows application

Here is a rephrased version of my issue:
Here is a screenshot of the result I'm looking for (from an older, non C#/WPF version of the application):
Looks like all the other grid-tree-views and what ObjectListView provides. But unfortunately I have some rules I have to follow:
WPF
MVVM
Just a DataGrid and its components must be used (no TreeView, ListView, etc.)
The Items are hold in an ObservableCollection<T> where T.Property1, T.Property2 etc hold the data for the columns of the DataGrid.
The lower Levels of an item are hold in T.PropertyChilds of type ObservableCollection<T> and are not known/filled beforehand. They must be loaded on the first exand of the item.
Here is a screenshot of similar data and what I've got so far in WPF/C#:
It looks like a standard DataGrid. But which columns it can hold, which property of T the columns are showing, which columns are currently visible, etc is defined by a own framework around the DataGrid which basically just adds columns to the public ObservableCollection<DataGridColumn> Columns Collection of a System.Windows.Controls.DataGrid.
My task is now to do a new class derived from DataGridColumn which can display and load the hierarchical data structure of my ViewModel described above.
The main problems I'm facing are as far as I can tell:
- how to visibly display the levels like a treeview in a DataGrid column
- how to process the loaded data from childs so they are shown as in the first screenshot above. Do I have to do a flat ObservableCollection<T> where I add the loaded ChildData and some extra properties like level and parent - or is it possible to define a kindo of a hierarchical data template for a DataGrid?
Thanks a lot
Soko

Can WPF CollectionViews be created to bring together multiple columns of data

I have about a dozen ObservableCollections that hold objects which have dates, singles and integers. All collections are of the same length and have data added and removed at the same time. One of the ObservableCollections is the main one and is needed when referring to the others.
Is there a way to use CollectionViews to bring 2 of these ObservableCollections together in such a way that they look like one ObservableCollection having the total of all of the original columns when data bound to a datagrid and/or chart? If so does anyone have an example?
Everything I have found shows the data from both sources being brought together by adding one on top of the other in what I would call a stack of data .
Thanks
Not pretty but I have a similar application.
Have a class with 5 base properties then a variable number of fields.
The fields I put in a List.
Can bind rows to a collection but not columns.
So I use a ListView Gridview where I build up the columns in code behind.
Bind the columns to Field[0], Field[1], ...
In you case you could have base class Bclass with the base Properties and a Property List
In your List<Fields> you just iterate the properties of the List<ExtensionClass>
Clearly the List<Bclass> needs to all have List<Extension> class with the same length in every item of the binding breaks.

How to properly manage a dynamic table of data for gui

So I need to display a DataGrid in WPF. I'm using RadGridView from Telerik and Caliburn.Micro framework using the MVVM strategy.
In my presentation there are differing number of columns, X+2 to be exact as there is always a Label column and a Total column and then X number of others that hold a decimal number.
I do know the number at runtime before I create the classes I need so that could help.
So I'm currently considering a few methods of doing this but some of them have drawbacks so I would love if someone could point me towards a solution.
Create a ViewModel class for each row and for each Cell. The X number will be a collection and binding to it is problematic. I would need to customize the RadGridView itsefl to actually manage this.
Create a DataTable an the run and bind to it. I haven't managed to make this work and not sure if RadGridView actually supports DataTable. This will also not allow me to keep metadata for each cell, something I need to be easily able to update the cells because column + row aren't the only distinguishing keys I need.
Somehow dynamically create a object with x+2 properties to bind to.
Are there any solutions, guides or something out there to help me here?

How to display in each ListBoxItem textblocks with binding to a filelds of a different tables

Greetings to all and sorry for my English!
I have a ListBox, it's ItemsSource = myClientsList.DefaultView. The Items of ListBox have a template (ControlTemplate), that is defined in a in a separate resource file.
Every Item contains a little TextBlock's, Text -property of each have a binding to fields of my Object myClientsList.
I need to add in a this item template more TexBlock's and each of them must have binding to fields of another my class myOrdersList. - (So I wish to view on each line of ListBox information from different tables of my database - this is a question).
Problem in that that ListBox's ItemsSource have a link to object myClientsList and I cann't set myOrderList to ItemSource of same ListBox. So i must find a way to specify TextBlock.DataContext wich inside ControlTemplate or how it's possible to solve this problem in another way?
p.s. I'm a new in .Net and WPF and probably have a mistakes in my explanation - sorry for it.
It sounds like you have a DataGrid type of display and want to add more columns in order to display the order information for a given client. If this is the case, you are going to have to do a couple of things. First, you will need to create a composite object that stores information for both entities into a single object (so each row of your control has all the data it needs to display). Secondly, I would recommend using an actual DataGrid control to display rows instead of templating a ListBoxItem. The ListView with a GridView built into the framework isn't great, so I would recommend the WPFToolkit's DataGrid for a free option.
There are two issues here, if I've understood the question: how do you create a single collection containing both Clients and Orders, and how do you display Clients and Orders in different ways within the same ListBox?
Regarding the first, you can do this using a CompositeCollection.
Regarding the second, define two DataTemplates instead of a ControlTemplate. As the key of each DataTemplate, use the type of the object it is going to present e.g.
<DataTemplate x:Key="{x:Type local:Client}">
Alternatively, use ItemsControl.ItemTemplateSelector to explicitly point at different DataTemplates depending on the type of item. Ot if you really have to use ControlTemplates, check out ItemsControl.ItemContainerStyleSelector.

WPF data binding - DataGridComboBoxColumn and ObjectDataProvider

I'm trying to code a WPF 4.0 DataGrid that matches a database table, with two entries in particular GroupID and SectionID... GroupID contains a collection of groups, and SectionID should be built from a table that takes a {GroupID, SectionID} keys and returns section information.
Binding the DataGridComboBoxColumn to the groups table to show the group names is easy using an ObjectDataProvider, but I can't work out how to do the sections given the fact I need to pass the relevant GroupID for the item into the GetSections() method the ObjectDataProvider is bound to...
Anybody else solved something similar?
Here is a link that explains a lot about a DataGridComboBoxColumn: link. Also, I would try to bind the DataGrid to an ObservableCollection of a class in which you add properties for each of your columns and then bind each column to a property of the class. By the way I've only done this in C# 3.5...

Resources