How to add columns dynamically to a TreeView - wpf

I'm fairly new to WPF and C#. I am developing a Tool, which reads data from a DB and puts it into a TreeView.
My class model looks like this:
class Developer //Contains a name, a list of categories and some additional info
class Category //Contains a name, a list of products and some additional info
class Product //Contains a name and some additional info
For now, the tool displays all the Names in a hierarchical manner. This is done via two HierarchicalDataTemplates and a DataTemplate for the leafs.
My question now is, if anyone has an idea how to add some simple columns to the TreeView which should display some double values. The problem is, that the number of additional info(double values) is set through user input. So, if the user wants to display a range of 3 months, I need the TreeView to add 6 columns. (column count = months * 2)
Or maybe someone knows a wpf custom control which suits my needs and works under vs10 and .NET4.0.
Thanks in Advance

The basic TreeView control doesn't support columns, there are specialized controls for this. Those controls are often called TreeList or TreeListView, as it includes the features of a tree and of a ListView. There are some commercial controls (the Telerik RadTreeListView comes to mind ) and there are some free versions floating around (one is in the Windows SDK itself, another one can be found here).
I've used none of them, so I can't tell which one is best suited for your problems, but I would give the last one a try, as it looks as it would solve them.

Related

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?

Silverlight WPF Generic Data Item

Basically I use lists to display information, these lists contain custom data items I have created, they all look similar and have some of the same controls in them, essentially they need to look the same colour, font etc. At the moment, I just seem to be repeating code over and over each time a change is needed i.e. colour.
I have been wondering if it would be a good idea to create a generic data item which all the lists use and then just collapse controls which aren't needed.
So I was going to create a user control called something like "GenericDataItem". This data item will contain all the controls that each data item would need, then use dependency properties to collapse controls not required.
My question is would this be the right way to go about this, or is there a better way?
Thanks.
Not sure I got the point, but using DataTemplateSelector could help you.

grid layout vs table control?

I need to display in my program number of similar statistics, like:
Name / Age / Salary / Position
John 30 1000 senior
Kate 18 100 intern
... .. .. ...
Totally I need to display several hundreads lines.
The question is what control should I use?
At least I know two options:
use Table control
use Grid layout (then dinamically add labels etc. to the grid)
I think with Grid I will automatically have "custom rendering" because I can add anything into Grid, not only "Label", but also buttons for example. However I'm not sure if I need such possibility.
But I need ability to sort the table by certain column.
So it seems "Table" better feets my needs, however I noticed that it seems that "Table" is not very popular in WPF (am I correct? why?)
So the question is "Should I use Table or there is someting better?" Is it possible to use databinding with Table?
I'm absolutely novice to WPF so sorry for any stupid questions :)
DataGrid and GridView were built for exactly that. When you bind a source it creates a table like row for each row in the source.
Either use a DataGrid or a ListView (with GridView), do not use a Grid, and what is this Table you speak of? If you mean this class, that can only be used in flow documents, which you do not need.
(See the documentation pages for examples or do some searching)

Designing a silverlight dashboard with mef - is it possible? (with dynamic loading of xaps)

I am just trying to wrap my head around MEF.
And as I am really going to love it ( I guess ) I started my first sample project and immediatly stumbled into a big problem and now I am asking myself if I can use MEF for my scenario at all and that is the following:
Imagine that one got some kind of dashboard with, let's say, five regions and above each region there are two comboboxes. The values in the first combobox represent different possible views (for example, chartControl, tableControl, pictureControl, ...) and the values of the second combobox represents the different data sources for the currently selected control.
As the controls are very big in size one wants to download them as needed.
If the user selects one comboboxitem the corresponding control xap should be loaded and displayed in this specific region. If the user selectes another control in the same combobox the control should be removed from the visualtree and the next control should be downloaded and displayed. If the user changes the selection in a different combobox the corresponding control should be loaded again only in this specific region, with perhaps different data.
And to make it a little more interesting - as this is some kind of dashboard one can change the layout from five regions to - for example - ten regions.
I've seen the video "MVVM with MEF in Silverlight Video Tutorial Part 2: Plugins and Metadata" ( http://csharperimage.jeremylikness.com/2010/03/mvvm-with-mef-in-silverlight-video_09.html ) but he is using an ItemsControl and is working with Visibility and he only got ONE region. So I think that this technique is not working for me...
Puh, I hope I could make myself clear!
Thanks a lot for any piece of information!!!
Greetings,
Tim.
Glenn Block has a series about using MEF to write a Silverlight Dashboard: http://codebetter.com/blogs/glenn.block/archive/2009/11/30/building-the-hello-mef-dashboard-in-silverlight-4-part-i.aspx

WinForms - How do I create a table using a custom control for each row?

I want to create a table representing data I have, but I want each row to have a custom display. I have developed a little custom control that represents a row and has a few items in it (text box, check box, progress bar), however how do I now in the main form create multiple instances of this for the data I have?
e.g. is there a winforms control I can use to do this? or do I have to take a panel or something and programmatically do it?
I do need to somehow take responses back. So if someone clicks on the button in the 4th row say then I'll need to be able to tell which row it was from.
As an aside would then be a way to BIND the above mentioned visualization of my data to the data itself, say housed in an Array?
thanks
I see two options here:
You can use a DataRepeater. This control can be found in the Microsoft Visual Basic Powerpack. It allows you to place controls on a template which gets copied for each item in the databound collection.
You can create a custom control and manually place one instance of it for each item in a collection, re-creating databinding for the controls in it. This requires you to either expose the controls inside publicly or as properties of the user control.
However, above options are mostly useful for non-tabular data. If your layout is strictly tabular (i. e. rectangular cells in a grid) then you can create a custom DataGridViewCell which takes some time to understand but not too much code. Putting a progress bar into such a cell shouldn't prove too difficult.

Resources