We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GGC and DataTable

Hi.

I have a following problem: I'm using GridGroupingControl for editing table. This table has an ID column which is integer and is generated by database.
Upon inserting new row in GridGroupingControl this ID column gets integer value from the control itself it seems. Column is not visible.
I want for all new records to have ID column with value DBNull.Value.

4 Replies

AD Administrator Syncfusion Team January 31, 2007 09:51 PM UTC

Hi Srdjan,

You can handle the SourceListRecordChanged event of the grid and set the value of the column using the e.Record.SetValue method. Try the below code snippet and let me know if you are looking something different.

private void gridGroupingControl1_SourceListRecordChanged(object sender, RecordChangedEventArgs e)
{
if( e.Action == RecordChangedType.Added )
e.Record.SetValue("ColumnName",DBNull.Value);
}

Best Regards,
Haneef


AD Administrator Syncfusion Team February 1, 2007 08:52 AM UTC

Thanks for your answer however it doesn't work. Your code is giving me following exception:

NotSupportedException: Id is read-only.

I'am using MS SQL database and Id is configured as int identity.


AD Administrator Syncfusion Team February 6, 2007 12:11 AM UTC

Hi ,

Before changing the cell value of the readonly column, You should change the Readonly property of the datacolumn to false. Here is a code snippet

private void gridGroupingControl1_SourceListRecordChanged(object sender, Syncfusion.Grouping.RecordChangedEventArgs e)
{
if( e.Action == RecordChangedType.Added )
{
DataTable dt = this.gridGroupingControl1.DataSource as DataTable;
dt.Columns["ID"].ReadOnly = false;
DataRowView row = e.Record.GetData() as DataRowView;
row.Row[0]= DBNull.Value ;
dt.Columns["ID"].ReadOnly = true;
}
}

Best regards,
Haneef


AD Administrator Syncfusion Team February 6, 2007 12:12 AM UTC

Hi ,

Before changing the cell value of the readonly column, You should change the Readonly property of the datacolumn to false. Here is a code snippet

private void gridGroupingControl1_SourceListRecordChanged(object sender, Syncfusion.Grouping.RecordChangedEventArgs e)
{
if( e.Action == RecordChangedType.Added )
{
DataTable dt = this.gridGroupingControl1.DataSource as DataTable;
dt.Columns["ID"].ReadOnly = false;
DataRowView row = e.Record.GetData() as DataRowView;
row.Row[0]= DBNull.Value ;
dt.Columns["ID"].ReadOnly = true;
}
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon