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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GGC and DataTable

Thread ID:

Created:

Updated:

Platform:

Replies:

55515 Jan 31,2007 01:18 PM UTC Feb 6,2007 12:12 AM UTC Windows Forms 4
loading
Tags: Tools
Administrator [Syncfusion]
Asked On January 31, 2007 01:18 PM UTC

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.

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;