Can anyone show me a quick example of creating a new fieldLayout in C# in the code behind?
I've tried something like this, but it doesn't seem to properly apply the fieldLayout I've created.
this.xamDataGrid.DataSource = GetData().DefaultView; Field field = new Field(); field.Name = "Column1";
FieldLayout fieldLayout = new FieldLayout(); fieldLayout.Fields.Add(field); this.xamDataGrid.FieldLayouts.Add(fieldLayout); this.xamDataGrid.DefaultFieldLayout = fieldLayout;
Thanks for any help.
Gabe
Working with FieldLayouts is more complicated than that. I suggest you read the documentation which provides an overview of the topic to better understand how the grid uses them.
http://help.infragistics.com/Help/NetAdvantage/WPF/2007.1/CLR3.X/HTML/xamData_Terms_Fields_Field_Layout.html
Hi John,
It is indeed complicated. In the documentation you linked
Field Layouts don't have names, but instead are matched by the series of Field objects they contain against the "attributes" it can identify on the Data Item.
Where can I find more information about what exactly the match logic is?
I am having some issues with field layout matching. I have two similar child bands, the schema of one is a superset of the schema of another. The grid insists giving the same lesser fieldlayout to both two bands.
It will be nice to know what property on which object the matching logic is referring to before making a decision, so I can debug this further. My data source is an IBindingList.
Thanks
I am not sure if there is any documentation yet that details the logic used to decide which FieldLayout the XamDataGrid will use to display data items. If you want to override the process, however, you can handle the control's AssigningFieldLayoutToItem event and set the e.FieldLayout property to whatever FieldLayout you want.
Josh
Thanks Josh, (big apologize, called you John by mistake, my bad)
I suppose i can try override that logic, but i prefer to stick with the default logic as i'm not doing something differently here. Perhaps i've bended something that I shouldn't have bended. Knowing the logic will help me greatly.
Do you know on top of your head that
Is it just comparing the keys? or first 20 columns? or all the columns? and how does it compare?
Cheers
I asked one of the XamDataGrid architects about this, and here is his reply:
The default matching logic is fairly complex but the first thing we try to match on is the Key of the FieldLayout. We initialize the Key of the FieldLayout differently depending on the data source, e.g. if the data source is a list of Customer objects then we will look to match a key of Customer Type. In the case where the data source is a DataView the Key of the FieldLayout is actually the instance of the DataView.If you want to see what Key is being used for your data source you can look at the Key properties of the FieldLayouts we generated (note: we generate these lazily as we encounter each record). If the key is predictable for your data source then you can create the FieldLayout ahead of time and set its Key property appropriately.
I hope that helps.
Hi Josh,
This is very useful info.
Thanks.