When using:
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
as opposed to:
<igDP:FieldLayout> <igDP:FieldLayout.Fields> </igDP:FieldLayout.Fields> </igDP:FieldLayout>
The problem is that converters won't work with the first way of laying out fields as the column is always blank if the type returned by the converter is different than the type the column name maps to, and if you use the second way, you get the following exception:
Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection
We are binding to the SelectedItem in a combobox and we must use the second way of binding to prevent this exception. Currently, we're creating an additional column to match the type, and am writing code in our model to pass this information forward. I'd prefer to use a converter. Is there a way to get converters to work using the first way?
Thanks,
Mike Malter
Hi Mike,
Does your converter return the same type every time? If so you can set some settings on the FieldSettings property of the Field that will allow you use a different type than what the column name maps to. The XAML code looks like this:
<igDP:Field Name="UnitPrice" Label="Unit Price" Converter="{StaticResource priceconv}"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamTextEditor}" EditAsType="{x:Type sys:String}"/> </igDP:Field.Settings></igDP:Field>
This field is mapped to a Property that is of type double but my converter returns a string so in order to show this new value I told the text editor used within the cell to expect a string using the EditAsType property.
Rob,
This is what I needed. Thank you very much. If the column type was a string and I wanted it to be an integer, would everything be the same except that sys:String would be sys:Integer?
Is there a listing of all of the igEditors and all the types somewhere?
Thanks again,
Mike.
I don't know if this list is exactly what you are looking for but it's a list of all the editors that the XamDataGrid uses by default depending on the type of data they are bound to.http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=xamData_Default_Editor_Types_for_Different_Data_Types.html
You can use this for changing the editor manually depending on the data type you want to show in the columns. For example, you asked if you could switch sys:String with sys:Integer and the answer is yes, the XamTextEditor will just convert the integer to a string on it's own. However you can also switch igEditors:XamTextEditor with igEditors:XamNumericEditor and then set the EditAsType to sys:Int32.
Let me know if you have any further questions on this matter.
Will do Rob, thanks for the link to the list, this was very helpful.