Hi,
I am new to Infragistics and I can't seem to figure how to make custom columns work in XamGrid.
I have the following code behind binding:
this.XamDataGrid1.DataSource = this.flatData.Tables[0].DefaultView;
Here's what I am doing in Xaml:
<Window x:Class="WPF_DataGrid.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:igEditors="http://infragistics.com/Editors" xmlns:Custom="clr-namespace:WPF_DataGrid" Title="Window1" Height="336" Width="559"> <Window.Resources> <igEditors:ComboBoxItemsProvider x:Key="cbipRatings"> <igEditors:ComboBoxItemsProvider.Items> <igEditors:ComboBoxDataItem DisplayText="5 Stars" Value="5 Stars" /> <igEditors:ComboBoxDataItem DisplayText="4 Stars" Value="4 Stars" /> <igEditors:ComboBoxDataItem DisplayText="3 Stars" Value="3 Stars" /> <igEditors:ComboBoxDataItem DisplayText="2 Stars" Value="2 Stars" /> <igEditors:ComboBoxDataItem DisplayText="1 Star" Value="1 Star" /> </igEditors:ComboBoxItemsProvider.Items> </igEditors:ComboBoxItemsProvider> <Custom:Customer x:Key="CustomerData"> </Custom:Customer> </Window.Resources> <Grid> <igDP:XamDataGrid Margin="0,12,0,0" Name="XamDataGrid1" IsGroupByAreaExpanded="False" IsEnabled="True" ScrollingMode="DeferredWithScrollTips" Theme="" AutoFit="True"> <!--<igDP:XamDataGrid.ViewSettings> <igDP:GridViewSettings /> </igDP:XamDataGrid.ViewSettings> <igDP:XamDataGrid.BindingGroup> <BindingGroup Name="{x:Null}" NotifyOnValidationError="False" /> </igDP:XamDataGrid.BindingGroup>--> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="CustomerID" Label="ID"/> <igDP:Field Name="CustomerName" Label="Name" /> <igDP:UnboundField Name="rating" Label="Rating"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource cbipRatings}"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:UnboundField> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid></Window>
the Grid doesn't show any data apart from the unbounded field. How can I re-arrange the columns and what do I need to do in order to make the child grid to work?
Hello,
Just in case anyone else comes upon this thread via search - an answer to the last question is available in the following thread:
http://forums.infragistics.com/forums/p/20684/74607.aspx
I'm having a similar problem where I've got FieldLayouts defined in a resource file. When I create a grid, I manually load the FieldLayout resource in using grid.FieldLayouts.add(LayoutResource);
The problem is that if I go to use this resource later to reload the grid, or on antoher grid, it errors saying the FieldLayout can not be moved to another DataPresenterBase.
No matter what I do in terms of clearing the FieldLayouts collection, or removing the layouts using grid.FieldLayout.Remove(grid.FieldLayout[0]); it always comes up with this error.
Surely there must be a way of reusing the FieldLayout resource, otherwise it seems utterly pointless having them as a resource.
You may have to manually remove it from the first XamDataGrid before adding it to the second.
I am having 2 xamdatgrid and their own schema and data.
During Runtime I want to add xamdatagrid2.FieldLayout into xamdatagrid1.fieldlayouts.add()
but it gives an error saying FieldLayout cannot be moved to another DataPresenterBase.
WPF doesn't raise errors when bindings fail. I guess this is so that you can throw anything at a control/template and whatever can be represented will, while what can't will just be ignored ... or handled by another template.
Usually the problem is because you're trying to bind to property names (or columns) that don't exist, or have a different case.
One trick I like to use is to explicitly specify a field layout to use. If any of the bindings fail, your application will stop and report which one.
private void XamDataGrid1_AssigningFieldLayoutToItem(object sender, Infragistics.Windows.DataPresenter.Events.AssigningFieldLayoutToItemEventArgs e){ // Hard-coded so that if there are any field binding issues it will fail and report the problem e.FieldLayout = XamDataGrid1.FieldLayouts["Main"]; // "Main" is the name of the FieldLayout}