I have created the fieldLayout. But when I use the Grid1.DataItems.Add() that doesn't seem to work with the fieldLayout that I created. How then do I add records?
There is FieldLayout.IsDefault property, but it doesn't change the grid's behavior.
XamDataGrid still assigns the very first suitable layout, no matter IsDefault = True or False.
Am I missing something? I even tried to assign XamDataGrid.DefaultLayout property in code, but to no avail.
I guess I must be blind looking for the samples and thus all of these dumb questions. Sorry...
Is there a single sample code in VB that shows creating the field layout and then binding to a datasource?
Or maybe just binding to a datasource and letting the grid do this.
When I say sample code, it run and actually work rather than a snip here and there that you would have to guess how they all go together.
The XamDataGrid will choose an appropriate field layout from its FieldLayouts collection by default. If it cannot find a correct field layout, it will create one (if the AutoGenerateFields is true).
If you want to have a greater control over this and assign a field layout yourself, you should use the AssignFieldLayoutToItem event of the XamDataGrid, where you can do this manually. The event args expose several useful properties in order to determine which layout to which item to assign.,
for example:
private void XamDataGrid_AssigningFieldLayoutToItem(object sender, Infragistics.Windows.DataPresenter.Events.AssigningFieldLayoutToItemEventArgs e)
{
if (e.Item is Person)
e.FieldLayout = xamDataGrid1.FieldLayouts["PersonLayout"];
}
As for the samples, in the online help, you will find both c# and vb code snippets.
How exactly do I tell the grid to use the field layout that is in the XML above? then how do I add a row to the grid? Can you please give me sample code that will do this?
The sample code you suggested is in C which is OK but Infragistics has always been good about detailed sample code in VB also. I dont see anything like that in the browser samples.
You can bind the XamDataGrid in two ways - through the DataSource property or through the DataItems collection. They are mutually exclusive so you should use only one of those at a time. It is recommended to set the DataSource property to a collection and work with it, because you have greater control over the collection and its type - for example - BindingList<T>, ObservableCollection<T>, ListCollectionView, etc.
You can also see a nice trick to get the xaml definition of the Fieldlayout without manually creating it here.
Moreover, you can see examples of basic as well as more advanced functionalities of the XamdataGrid (binding to different data sources is also included) in the XamFeatureBrowser from the local samples.