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?
Hello,
Does the definition of the underlying object match the fields in this FieldLayout? Have you set AutoGenerateFields to false. The XamDataGrid by default would generate a new FieldLayout if the new object does not match the current layout.
I used the add collection and add field GUI interface from the properties for the grid. this is as close as the old UtlraWinGrid has to a designer I guess.
Anyway it created the XAML and that looks good.
What method is used to add data? the only one I have found is requires a collection object, which I guess is already defined... I am just not used to the WPF yet and basically lost trying to get this working.
The generated XAML is below.
Thanks for the help!
<igDP:XamDataGrid Canvas.Left="50" Canvas.Top="301" Height="136" Name="Grid1" Width="435" DataContext="{Binding}"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings CellClickAction="SelectRecord"/> </igDP:FieldLayout.FieldSettings> <igDP:FieldLayout.Fields> <igDP:Field Name="name" Label="Name"/> <igDP:Field Name="department" Label="Dept." /> <igDP:Field Name="salary" Label="Salary"/> <igDP:Field Name="email" Label="Email"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
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.
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.
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.