hi,
I've a GDBG which datasource is a datatable.
i want to delete row 1 and 9, but the rows deleted are row 1 and 10..
The following is my code..
foreach (GridRangeInfo r in this.dgCutLot.Selections.GetSelectedRows(true, true))
{
dgCutLot.DeleteRecordsAtRowIndex(r.Top, r.Bottom);
}
Please help, thanks!
AD
Administrator
Syncfusion Team
March 20, 2007 02:34 PM UTC
Hi Lim,
The DeleteRecordsAtRowIndex method removes the records at specfied rows from the grid and its underlying datasource. Before the rows are deleted, a cencelable RowDeleting event is raised. After the rows are deleted, a RowDeleted event is raised. It takes two argument.
first
- The first row to delete from the grid.
last
- The last row to delete from the grid.
If you want to delete records based on its zero base position of the grid then use RemoveRecords method from GridModelDataBinder class. The Binder.RemoveRecords method removes the specified records from the datasource (without sending a RowsDeleting event; use DeleteRecordsAtRowIndex instead if you need it. It also takes two argument.
first
-The zero-based position of the first record.
last
-The zero-based position of the last record.
Best Regards,
Haneef
AD
Administrator
Syncfusion Team
March 21, 2007 05:38 AM UTC
Hi Haneef ,
The problem is still exists.. My code is as following:
foreach (GridRangeInfo r in this.dgCutLot.Selections.GetSelectedRows(true, true))
{
//dgCutLot.DeleteRecordsAtRowIndex(r.Top, r.Bottom);
dgCutLot.Binder.RemoveRecords(r.Top-1, r.Bottom-1);
}
The GridRangeInfo r is R1 and R10. There are total of 10 records and i want to delete Row 1 and Row 10, but after Row 1 is deleted the index was changed.. The error code is "There is no row at position 9".
Please help! thanks!
Regards,
lim
AD
Administrator
Syncfusion Team
March 21, 2007 04:39 PM UTC
Hi Lim,
You can try this code.
foreach (GridRangeInfo r in this.gridDataBoundGrid1.Model.Selections.GetSelectedRows(true, true))
{
int iTotalRows = this.gridDataBoundGrid1.Model.RowCount;
int iBottom = r.Bottom -1;
if (this.gridDataBoundGrid1.EnableAddNew)
iTotalRows -= 1;
if (r.Top > iTotalRows)
return;
else if (r.Bottom > iTotalRows)
iBottom = iTotalRows -1;
this.gridDataBoundGrid1.Binder.RemoveRecords(r.Top - 1, iBottom );
}
Best regards,
Haneef