WPF Grid Control, pivot child data - c#

Is there an effective control or method whereby I could bind a grid to a datasource, and the grid could (for lack of a better word) "pivot" a property which contains a collection to display on the same row as the parent?
Example: Datasource object has 3 properties, Name, Status, and StatusDateCollection.
StatusDateCollection could contain any number of items.
I want to bind to a grid which would display something like:
Test 1 Active 1/1/2016 2/1/2016 3/1/2016
Test 2 Inactive 7/1/2016 8/1/2016
Test 3 Suspended 3/1/2015 4/1/2015 5/1/2015 6/1/2015 7/1/2015
Do any of the popular grid controls (Telerik, Infragistics, Syncfusion, etc.) provide a way to do this?

In Xceed WPF DataGrid, Cell templates can be defined as anyway you like. I'm sure any WPF datagrid enables this in someway. So you can define a cell template for that column, where the template will display the collection data in anyway you want.

Related

Bound DataGridView with combo box [duplicate]

I have a DataGridView in a C# WinForms app that is DataBound at runtime (through Form_Load) to a custom Object.
In the design view of the DataGridView I have no columns set up.
When the Form loads the the columns are automatically created based on the data in the Custom object that it is DataBound to.
My question is how can I control the the Columns that are automatically created.
For example if I want one of the columns to be a DataGridViewLinkColumn instead of the DataGridViewTextBoxColumn that is automatically created?
The default columns are based on the data-type. I haven't checked, but for a link you could try exposing the data as Uri, but that might be hopeful. Really, if you want a specific type of column - add the columns through code and set DataGridView.AutoGenerateColumns to false.
As Andrew implies; normally something like reflection is used to generate the columns, and you'll get a column for every (browsable + public + readable) property. There is a layer of abstraction on top of this if you need, but this won't help with adding a hyperlink column.
You can pre-create your columns in the designer. If the name of the column matches the name of the property the column will end up bound to, the databinding will take care of the DGV population for you as before.

DataGridView Column with multiple controls (Radiobuttons, check boxes, list drop downs, etc.)

I'm interested in creating a DataGridView Column that contains multiple control objects. Specifically, I'd like to build a Column that contains: a text field, a list dropdown, a few checkboxes, and a few radio buttons.
I did some research and came across this page, http://www.codemag.com/article/0707061, which gives a general idea for what I need to do but is it little bit more complex than what I'm looking for. I've not been able to find any examples of adding multiple control objects to a single column.
I'm looking for other resources that I can reference to help me with this task.
This is being done in winforms.
Looks like I'll need to build a custom DataViewGridCell for each control that I want. I can then set the column's .CellTemplate to that Cell. Can a column have multiple CellTemplates?
The short version is like you suggested. It would be to create a custom ViewCell that Inherts from DataGridViewCell contains each of the controls you want to add. Then set the template to that column.
DataGridViewColumn column = dataGridView.Columns[indexForYourColumn];
DataGridViewCell cell = new YourCustomDataGridViewCell();
column.CellTemplate = cell;
Some specific resources to use CellTemplate, CustomControls1, CustomControls2

WPF DataGrid with multiple columns in group row

I am trying to work with native WPF DataGrid control to show hierarchical data. Similar to the structure of data shown in image below (ignore the cosmetics) where :
GroupRows have same number of columns as the main grid.
Group row do not repeat column headers for every group, instead just flexible enough to show a summary in each column.
Expanding the column headers should resize all the rows in the grid including group row.
Reading up some examples I can see there is option to define a header template for each group row but I am not sure how get above points work together.
I have stumbled upon some implementations of reusable wpf controls that have heavy codebase I am reluctant to inherit just to get some minimalistic features.
Any help or pointers would be very useful.

Change WPF DataGrid Cell Font based on comparison of cell values

I am new to using the WPF DataGrid and I'm kind of lost. What I have is a DataTable with numeric values to which I bind the DataGrid via a DataView. What I want to do is compare the values of each column, and make the cell that has the bigger value per column, bold. (e.g. Who wins in each category)
There's no ObservableCollection, no fancy stuff. I'm just adding data to a DataTable the "manual" way, getting the values cell-by-cell from an SQLite database DataTable response. Even the columns are created programatically, and not via XAML. I have almost no experience in XAML, so don't assume I've worked with Triggers or anything.
How would I go about doing something like this?
Start from small examples. You can create some test data, with which you can try data binding technique. Try to style some parts of DataGrid: change colors of Foreground, add some Border with BorderBrush. Explore WPF yourself - it is hard only for the first view.
Here is some how to:
Use converters in WPF
Use binding
Use styles and templates for DataGrid elements
Use MVVM

Dynamic DataGrid columns in WPF DataGrid based on the underlying set of data (and their type)

I've got kind of a conceptual question. I am in the process of wrapping some statistics classes I wrote into WPF.
For that I have two DataGrid(-Views, currently in WinForms). In one DataGrid each row represents a column in the other. There I can set-up different variables (as in mathematical/statistical variables) with fields like "Header", "DataType", "ValidationBehaviour", "DisplayType". There I can also set-up how it should be displayed. Some Columns can automatically be set to ComboBoxColumns, some TextBoxColumns, and so on and so forth.
So, now once I've set-up these Columns I can go to the other grid and enter my data. I may, for instance, have generated (in grid 1) one Column called "Annual Gross Salary" with input of numerical values. Another Column called "Education" with "0=NoEducation", "1=College Level", "3=Universitary" etc. These labels are displayed as text in the combobox and my statistics engine behind then selects the respective value (0-3) for calculations (i.e. ordinal, nominal variables).
Sooo. In WinForms I could basically generate all the columns by hand in code and then add my data in the respective cells/rows. Now in WPF I thought that must be easy to realise. However, yesterday I got started with ICustomPropertyDescriptor which (maybe I was too thick) didn't give me the results I was looking for.
Basically, I just need to be able to dynamically generate columns (and rows) with different Layout, Controls (ComboBox, simple Input, DateTimes) based on the data that I have. But I don't really know how to go about it?
So here in summary:
DataGrid 1
Purpose is to display columns that have been specified in DataGrid 2
In rows, the user can add any kind of data in the rows below the columns that is allowed as to the columns specifications
DataGrid 2
Each row in this grid represents a column in DataGrid 1
Contains fields like Name/Header, DataType, Validation Behaviour, Default Value, Data Formatting, etc.
Also contains a function to be able to set-up how it should be displayed. The user can select from, for instance, ComboBoxColumn (and also add the available options), DateTime, normal TextBox, CheckBox etc.
After finishing adding a row it will automatically appear as a new column in DataGrid 1
I'd appreciate any kind of pointer into the right direction. Thanks very, very much in advance! :)
Look up DataTemplates. They do exactly this. The UI is determined by the related type.
Here is an MSDN article...

Categories