datagrid view with 2 data sources - wpf

I'm writing an app where i want to compare the data from two different data sources to see if there are any differences. All examples i have seen of similar functionality always place two datagrids next to each other so that you can see each row side by side.
This makes it very hard to spot differences. What i would like to do is to show the rows one above the other in agridview. That is, alternate the rows in the datagrid to be bound to one then the other datasource as a matched pair. Actually i would also like to add a check box to one row so that the pair can be selected for futher processing.
I know that the controls are very customisable but is something like this possible ? Or would i need to combine the two data sources into a single one and then bind it ?

What you're looking for is MultiBinding
This will enable you to bind multiple items and by using a converter to return a new single item. So essentially, yes, you will combine the two data sources into one inside the converter.

Related

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.

DataGrid that masks columns

Can a DataGrid dynamically mask the columns to be displayed?
Current Setup
DataGrid <--Binding--> Collection<Customer>
The type Customer has about 100 different fields defined.
Different views need to display different sets of columns (about 20 out of 100), chosen somehow dynamically, of the same Collection<Customer>.
Is there an option to dynamically mask the fields that will be displayed as columns in the DataGrid? Ideally, I want to use Infragistics' xamDataGrid, but any solution for a DataGrid will be a good starting point.
There are other similar questions out there, but they deal with either column filtering or variable number of rows.
If you are defining different views in code you could create different FieldLayouts and use the FieldLayout for the view that is needed. This would require setting the FieldLayout to be used in code by adding the layout to be used to the FieldLayouts collection.
If you are allowing the end user to define what is in the view, then you will likely want to define all possible fields and then allow the fields to be hidden or shown with the Field Chooser.
There are methods for saving and loading customizations to the fields that you can use to persist the layouts.

Creating an Empty DataGrid

I was wondering what the best way was to create an empty datagrid.
For example after you have hit new in excel, You have a grid with empty rows and columns.
I am using c# with WPF and .net 4.0.
Thank you.
As the comments have suggested, a datagrid is not a spreadsheet, but a method to display / edit existing data. That said if you want something similar, feel free to populate a collection with default / 'empty' objects and bind that to your grid. It just means that after working with the data, you will have to define a method to capture only the edited rows. This still means that the column-bound properties of your class need to be known ahead of time.
A DataGrid is used to display a collection. If you want to create an individual row DataGrid is not really the right tool. You could but a single empty row in the DataGrid using a collection of only on row. There is a lot of guidance on Master Detail on MSDN. If you don't know how many columns at design time you could used a DataGrid to turn the row vertical with column 1 as name and column as value so now you have one record but with a collection of fields.

wpf datagrid aggregating

Is it possible to get aggregation with the standard wpf datagrid, similar to the image below (A Telerik Grid)? I dont need summing values, just aggregating values according to one or more columns.
You can use a CollectionView for this, apart from its documentation see linked articles like this. To properly display the Groups you may want to specify a GroupStyle.

Dynamic row and column span in WPF DataGrid

I'm working on a new project where the design calls for dynamic rows and columns displayed in some form of grid. I think I can accomplish this very hackishly using the plain ol' Grid, but it seems like it should be possible using a "real" grid.
In my mockup, I circled the tricky bit in red. Under column 1, I have effectively 2 columns of data. The problem is the fact that my data in column 1 can span multiple rows. And the fact that column one is really two pseudo columns and each one can span a different number of rows independently. Note: the data is fake and inconsequential. I'm open to ideas for a good implementation. I can fall back to the Grid and do this all in code behind, I'm open to purchasing a datagrid that may have more power than the DataGrid and my absolute last resort/preference is to restructure this format to something a little more doable.
Thank you for any ideas you can provide.
Most commercial WPF DataGrid implementations handle hierarchical data like this. For example, Telerik's DataGrid (part of RadControls for WPF) supports hierarchical data in multiple formats.
Typically, the default styling is a bit different than yours above, but can be adapted to that format via styling.

Resources