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.

delete problem in Datagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

58145 Mar 19,2007 11:43 PM Mar 21,2007 12:39 PM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On March 19, 2007 11:43 PM

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!

Administrator [Syncfusion]
Replied On March 20, 2007 10:34 AM

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

Administrator [Syncfusion]
Replied On March 21, 2007 01:38 AM

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

Administrator [Syncfusion]
Replied On March 21, 2007 12:39 PM

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

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.

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.

;