GridAddNewRecord in GGC

Dear all, how can i add a new row via a button click (grid is set to readonly !) ? Thanks Kai

4 Replies

AD Administrator Syncfusion Team July 11, 2006 05:33 PM UTC

Hi Kai, Try this code to add a new record in a grid. Here is a code snippet. DataTable dt = this.gridGroupingControl1.DataSource as DataTable; this.gridGroupingControl1.BeginUpdate(); DataRow dr = dt.NewRow(); dt.Rows.Add(new object[]{}); dt.AcceptChanges(); this.gridGroupingControl1.EndUpdate(true); Let me know if this helps. Best Regards, Haneef


KA Kai Abesser July 11, 2006 07:21 PM UTC

Dear Haneef, i work with typed datasets, i.e.: this.analyseGrid.BeginUpdate(); dsXLAuftragAnalyseView.XLAuftragMethodeDataTable dt = this.analyseGrid.DataSource as dsXLAuftragAnalyseView.XLAuftragMethodeDataTable; dsXLAuftragAnalyseView.XLAuftragMethodeRow row = dt.NewXLAuftragMethodeRow(); row.fIsAktiv = true; ... this.dsXLAuftragAnalyseView.XLAuftragMethode.AddXLAuftragMethodeRow(row); this.xlAuftragMethodeTableAdapter.Update(this.dsXLAuftragAnalyseView); this.dsXLAuftragAnalyseView.AcceptChanges(); this.analyseGrid.EndUpdate(true); but i get an exception, that dt is null. when i add the row direct in my dataset, anything works, but the grid dosen´t reflect the new record ... regards kai


AD Administrator Syncfusion Team July 11, 2006 09:49 PM UTC

Hi Kai, Try this code snippet to add a record through grouping table. Please find the code snippet below. //Form''s Load event this.gridGroupingControl1.NestedTableGroupOptions.ShowAddNewRecordBeforeDetails = true; this.gridGroupingControl1.TopLevelGroupOptions.ShowAddNewRecordBeforeDetails = true; //button''s click event 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"); r.EndEdit(); } } } break; } } table.EndEdit(); Let me know if this helps. Best Regards, Haneef


KA Kai Abesser July 12, 2006 10:43 AM UTC

Hi Haneef, intressting way ... thanks it works ... regards Kai

Loader.
Up arrow icon