Adding a new record to GridGroupingControl with AllowNew = true;

If I set for my GridGroupingControl such properties as:

gridGroupingControl1.TableDescriptor.AllowNew = true;
gridGroupingControl1.TableDescriptor.AllowEdit = true;

In the top oof my grid appears the row for adding new records to my grid and to my DataTable also that was binded to that grid, and why when I input only one value to some column and set focus to the next cell in this row - grid automaticaly adds this not completed record with values to the end of his collection and it appears as new added as last record - and how can I to control adding the new record to my grid, how can I Cancel(Reject) the adding if my record edditing is not completed yet???

Best regards, Alexander.

5 Replies

AD Administrator Syncfusion Team October 4, 2006 06:13 AM UTC

Hi Alexander,

You need to handle the CurrentRecordContextChange event and set the e.Cancel to TRUE when the record is incomplete. Below is a code snippet

private void gridCurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e)
{
if( e.Record != null && e.Record.Kind == DisplayElementKind.AddNewRecord
&& e.Action == CurrentRecordAction.EndEditCalled )
{
DataRowView drv = e.Record.GetData() as DataRowView;

for(int i = 0 ;i < drv.Row.ItemArray.Length; i++)
{
object cellvalue = drv[i];
if( cellvalue == null || cellvalue.ToString() == string.Empty )
{
e.Cancel = true;
break;
}
}
}
}

Thanks,
Haneef


AL Alexander October 4, 2006 11:00 AM UTC

Thanks it is work okey!!!

But how I can to set value programmaticaly in this new row until it is not added to the grid collection???

When I try to do this:

gridGroupingControl1.TableControl.Table.CurrentRecord.SetValue("Candidate_id", 33);

an error occured(exception) - this row hasn''t been added!!!


AD Administrator Syncfusion Team October 4, 2006 12:11 PM UTC

Hi Alexander,

Try these code snippet to set the newvalue to the AddNewRecord of the GridTable.

GridTable table = this.gridGroupingControl1.GetTable("YourTableName");
table.BeginEdit();

Record r = null;
foreach(Element el in table.DisplayElements)
{
if( el.Kind == DisplayElementKind.AddNewRecord )
{
r = el.ParentRecord;
r.SetCurrent();
if( r != null)
{
if (r.IsCurrent)
{
r.BeginEdit();
if (r.IsEditing)
{
r.SetValue("YourColumnName", "BX");
r.SetValue("YourColName", "ID");
//If you want to add the record to the table call EndEdit...
//r.EndEdit();
}
}
}
break;
}
}
//If you want to add the record to the table call EndEdit...
//table.EndEdit();


Best Regards,
Haneef


AL Alexander October 4, 2006 02:36 PM UTC

Is the RowCount in GridGroupingControl of the NewRow(row for adding new records) is always equal(=) 4(four)???

Or how can I to know is NewRow in Grid now is editing????


AD Administrator Syncfusion Team October 5, 2006 07:01 AM UTC

Hi Alexander,

Is the RowCount in GridGroupingControl of the NewRow(row for adding new records) is always equal(=) 4(four)???
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
No. It depends on the GroupCaptionRow, ColumnHeaderRow and display order of the GroupingEngine.

How can I to know is NewRow in Grid now is editing????

>>>>>>>>>>>>>>>>
You can use the IsEditing property of the Record to determine the editing state of the record.

this.grid.Table.AddNewRecord.IsEditing.

//For 4th record
this.grid.Table.Records[4].IsEditing.

Thanks,
Haneef

Loader.
Up arrow icon