I was expecting this to be fairly straightforward but not sure what's wrong. I am using version 10.2.20102.2005. Here is my sample code
XAML:
<ig:XamGrid x:Name="igGrid" AutoGenerateColumns="False" Height="150"> <ig:XamGrid.Columns> <ig:TextColumn Key="WorksheetID" HeaderText="Worksheet Id"/> <ig:TextColumn Key="LineItemID" HeaderText="LineItem Id"/> <ig:TextColumn Key="GOID" HeaderText="GOID"/> </ig:XamGrid.Columns>
</ig:XamGrid>
C# code:
public void FetchMyWorkSheets() { List<Worksheet> worksheets = new List<Worksheet>(); for (int i = 0; i < 10; i++) { Worksheet ws = new MyWorksheet(); ws.WorksheetID = i; ws.LineItemtID = i * i; ws.GOID = i + i; worksheets.Add(ws); } igGrid.ItemsSource = worksheets; }
public class Worksheet { public int WorksheetID { get; set; } public int LineItemtID { get; set; } public int GOID { get; set; } }
Exception:
Following exception is thrown at line igGrid.ItemsSource = worksheets;
Infragistics.Controls.Grids.InvalidColumnKeyException was unhandled by user code Message=The following key(s) do not correspond with the DataSource: "LineItemID". If you'd like to add additional columns, please use the UnboundColumn type. StackTrace: at Infragistics.Controls.Grids.RowsManager.InitializeData() at Infragistics.Controls.Grids.RowsManager.SetupDataManager() at Infragistics.Controls.Grids.RowsManager.EnsureDataManager() at Infragistics.Controls.Grids.RowsManager.OnItemsSourceChanged() at Infragistics.Controls.Grids.RowsManager.set_ItemsSource(IEnumerable value) at Infragistics.Controls.Grids.XamGrid.ApplyItemSource(IEnumerable itemSource) at Infragistics.Controls.Grids.XamGrid.ItemsSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Infragistics.Controls.Grids.XamGrid.set_ItemsSource(IEnumerable value) at Jenzabar.EX.SLTestPage.FetchMyWorkSheets() at Jenzabar.EX.SLTestPage.btnFetch_Click(Object sender, RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) InnerException:
Hi,
This is because your WorkSheet object doesn't have "LineItemID" property. Note that you have "LineItemtID" (the "t" before ID) defined in WorkSheet.
Hope this helps
Ok, I messed up with a typo in my sample code but ironically I got the same exception that I am getting in my actual code. Here are code snippets and info from actual code I am working on. In my XAML Code below I have both Infragistics and MS grids side by side and binding them to same data source.
<ig:XamGrid x:Name="igGrid" AutoGenerateColumns="False" Height="150"> <ig:XamGrid.Columns> <ig:TextColumn Key="WorksheetID" HeaderText="Worksheet Id"/> <ig:TextColumn Key="LineItemID" HeaderText="LineItem Id"/> <ig:TextColumn Key="GOID" HeaderText="GOID"/> </ig:XamGrid.Columns> </ig:XamGrid> <data:DataGrid x:Name="dg" Style="{StaticResource grid}" AutoGenerateColumns="False" HeadersVisibility="Column"> <data:DataGrid.Columns> <data:DataGridTextColumn Binding="{Binding WorksheetID}" Header="Worksheet Id" IsReadOnly="True" /> <data:DataGridTextColumn Binding="{Binding LineItemID}" Header="LineItem Id" /> <data:DataGridTextColumn Binding="{Binding GOID}" Header="GOID" /> </data:DataGrid.Columns> </data:DataGrid>
My C# code binds both grids to same data source. MS grid works without any problem but I get the same exception for infragistics.
C# Code:
this.dg.ItemsSource = e.ResolvedEntities; this.igGrid.ItemsSource = e.ResolvedEntities;
ResolvedEntities is a List<WorksheetLineItem> and WorksheetLineItem is a complex type. See screenshot below. Please note the immediate window shows that ResolvedEntities is populated.
And finally the full exception details.
Infragistics.Controls.Grids.InvalidColumnKeyException was unhandled by user code Message=The following key(s) do not correspond with the DataSource: "WorksheetID". If you'd like to add additional columns, please use the UnboundColumn type. StackTrace: at Infragistics.Controls.Grids.RowsManager.InitializeData() at Infragistics.Controls.Grids.RowsManager.SetupDataManager() at Infragistics.Controls.Grids.RowsManager.EnsureDataManager() at Infragistics.Controls.Grids.RowsManager.OnItemsSourceChanged() at Infragistics.Controls.Grids.RowsManager.set_ItemsSource(IEnumerable value) at Infragistics.Controls.Grids.XamGrid.ApplyItemSource(IEnumerable itemSource) at Infragistics.Controls.Grids.XamGrid.ItemsSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue) at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation) at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at Infragistics.Controls.Grids.XamGrid.set_ItemsSource(IEnumerable value) at Jenzabar.EX.SLTestPage.WorksheetLineItems_PendingEntityListResolved(Object sender, PendingEntityListResolvedEventArgs`1 e) at IdeaBlade.EntityModel.RelatedEntityList`1.OnPendingEntityListResolved(RelatedEntityList`1 resolvedEntities) at IdeaBlade.EntityModel.ListEntityReference`1.InformPendingEntityListOfRealEntityList(RelatedEntityList`1 realEntityList) at IdeaBlade.EntityModel.ListEntityReference`1.QueryCallback(EntityQueryOperation op) at IdeaBlade.EntityModel.EntityQueryOperation.IdeaBlade.EntityModel.IHasAsyncEventArgs.OnCompleted() at IdeaBlade.EntityModel.AsyncProcessor`1.<>c__DisplayClass2.<.ctor>b__0(TArgs args) at IdeaBlade.EntityModel.AsyncProcessor`1.Signal() at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x) InnerException: