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; } } }
}
Just Recursive pointers across different threads.Else nothing.
I have been looking for the help last 2 to three weeks but unable to solve this problem.
I want to provide the functionality of add,update and delete records in xamDataGrid just like GridView control in 2.0. Also could some one please write a demo application of doing these functionalities.
I used following Method
TestDataGrid.xaml.cs
ConnectionClass cc = new ConnectionClass(); conn = new SqlConnection(); conn = cc.makeConnection(); da = new SqlDataAdapter("Select * From TestControls", conn); ds = new DataSet(); da.Fill(ds); //dgEvents.DataSource = ds.Tables[0].AsEnumerable(); DataView dv = new DataView(ds.Tables[0]); dv.AllowDelete = true; dv.AllowEdit = true; dv.AllowNew = true; dv.ApplyDefaultSort = true; DataTable datatable = new DataTable(); datatable = dv.Table.AsDataView().ToTable(); dgEvents.DataSource = datatable.AsEnumerable();
TestDataGrid.xaml
<infra:XamDataGrid Name="dgEvents" AutoFit="True" RecordAdding="dgEvents_RecordAdding" RecordsDeleted="dgEvents_RecordsDeleted" RecordUpdating="dgEvents_RecordUpdating" Margin="0,0,0,52"> <infra:XamDataGrid.ViewSettings> <infra:GridViewSettings AllowDrop="True"> <infra:GridViewSettings.ContextMenu> <ContextMenu /> </infra:GridViewSettings.ContextMenu> </infra:GridViewSettings> </infra:XamDataGrid.ViewSettings> </infra:XamDataGrid>
Nevermind. Yes, after I removed the constructor parameters, it started working. Thanks.
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
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.