What am I doing wrong here? I have been able to get the new row thing to work using a dataset, but this time I am using custom objects. I even changed my one class to inherit from BindingList<> instead of ObservableCollection<> and it still doesn't appear. Here is my code...
<igDP:XamDataGrid Grid.Row="0" Margin="10,5,10,5" Background="White" Theme="Aero" x:Name="MetrixRelationDefGrid"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings MaxSelectedRecords="1" AddNewRecordLocation="OnTopFixed" AllowAddNew="True" AutoGenerateFields="False"> <igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="75" /> <ColumnDefinition Width="150" /> <ColumnDefinition Width="150" /> </Grid.ColumnDefinitions> </Grid> </ItemsPanelTemplate> </igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate> </igDP:FieldLayoutSettings> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="MetrixRelationDef"> <igDP:FieldLayout.Fields> <igDP:Field Name="IsSelected" Label="Selected"/> <igDP:Field Name="ParentTableName" Label="Parent Table"/> <igDP:Field Name="RelatedTableName" Label="Related Table"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Binding bd = new Binding(); bd.Source = metrixRelationDefs; MetrixRelationDefGrid.SetBinding(XamDataGrid.DataSourceProperty, bd);
using System;using System.Collections.Generic;using System.Text;using System.Collections.ObjectModel;using System.ComponentModel;
namespace MetrixStudio.CustomObjects{ public class MetrixRelationDefs : BindingList<MetrixRelationDef> { }
public class MetrixRelationDef { private string _parentTableName; private string _relatedTableName; private bool _isSelected; private MetrixRelationMaps _relationMaps = new MetrixRelationMaps(); private MetrixRelationConstraints _relationConstraints = new MetrixRelationConstraints();
public MetrixRelationDef(string parentTableName, string relatedTableName) { this.ParentTableName = parentTableName; this.RelatedTableName = relatedTableName; }
public MetrixRelationConstraints RelationConstraints { get { return _relationConstraints; } set { _relationConstraints = value; } }
public MetrixRelationMaps RelationMaps { get { return _relationMaps; } set { _relationMaps = value; } }
public bool IsSelected { get { return _isSelected; } set { _isSelected = value; } }
public string ParentTableName { get { return _parentTableName; } set { _parentTableName = value; } }
public string RelatedTableName { get { return _relatedTableName; } set { _relatedTableName = value; } } }
}
IBindingList is required to support add new functionality. You may want to take a look at this thread - http://news.infragistics.com/forums/t/6053.aspx. Basically, BindingList<T> will not support automatic addnew support unless your T has a public parameterless ctor which in your example it does not. Otherwise you need to handle the AddingNew event of your BindingList<T> and set the e.NewObject to a new instance of the object.
What does that mean " has a public parameterless ctor ". Can you show me an example using my code. I will change it if needed. Do you mean that the constructor can't have parameters?
Thanks