In you example how handling hierarchical dataset you are using predefine classes (Customer, Order and OrderDetails). What should I use to create dynamically and load with data and then bind to datagrid? Please provide example.
Thanks.
By "dynamically" do you mean with anonymous types? If so you wouldn't be able to bind to a list of that data.
Can I use Dictionary with key as string and value as object?
I have attached a small sample that demonstrates binding the XamGrid to a dynamically created ObservableCollection of Dictionary<string, object> items. This sample uses the same approach as the documentation Steve linked to (http://help.infragistics.com/NetAdvantage/Silverlight/Current/CLR4.0/?page=xamGrid_Support_for_String_Indexers.html) but has a few small tweaks to work with dynamic data.
First, I had to make sure that I set the DataContext of my XamGrid to be the ObservableCollection and bind the grid to this data. I also make sure to set AutoGenerateColumns to false. This is needed as the XamGrid doesn't know how to display Dictionaries without the use of indexers.
Next, after I generate my data, I add the columns to the grid. I created a recursive function for this that checks the DataType of the underlying data for the column so that I can add the correct column type to the grid. For each column I set the Key property of the column equal to an indexer for an item in the Dictionary. If I find that my Dictionary item is a collection then I call the recursive function again, this time adding columns to a ColumnLayout rather than directly to the XamGrid.
Please take note that I had to use Dictionary<string, object> to form my column structure so that I could have support for child rows. Due to this, my sample will not support filtering and summaries; GroupBy and sorting should still work, though.
Please let me know if I can be of any further assistance with this matter.
How can I use validation for empty field, for numeric value and for range when bind of BindableCollection<ObservableDictionary<string, object>> to xamGrid?
Hello,
If you are unable to implement error validation on your underlying data, one possible option would be to mimic error processing and set Visual State of the underlying editor to Invalid whenever the value does not pass the editing.
I have attached a sample illustrating this. In the sample, whenever the value does not pass validation the underlying editor is retrieved and the Tag of the editor is set to the error message and the visual state is set to “InvalidFocused”. In addition, the validation tooltip template is overridden so that the text of the tooltip is set to the tag of the control.
Sincerely,ValerieDeveloper Support Engineer Infragisticswww.infragistics.com/support
How can I flag the error? Set red border, show message on grid.
Hello Igormezh,
Normally you would implement IDataErrorInfo on the class that the grid is bound for data validation. In the case of a grid bound to a dictionary you would need to implement your data validation logic in the CellExitingEditMode event. You can then cancel the event if the value does not meet your validation criteria by setting e.Cancel = true;