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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I delete multiple selected ranges of rows in a GridDataBoundGrid?

Platform: WinForms |
Control: GridDataBoundGrid(Classic) |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014

 

Grid's row deleting support only handles a single range. You can see this in the rowsdeleting event which only have From and To members which will not handle multiple ranges.The attached sample handles the RowsDeleting event to delete multiple ranges of rows.

C#

bool indeleting = false;

private void gridDataBoundGrid1_RowsDeleting(object sender, Syncfusion.Windows.Forms.Grid.GridRowRangeEventArgs e)

{

if(!indeleting)

{

indeleting = true;

GridRangeInfoList rangeList = this.gridDataBoundGrid1.Selections.GetSelectedRows(true, false);

if(rangeList.Count > 1)

{

this.gridDataBoundGrid1.Selections.Clear();

int nRanges = rangeList.Count;

for(int i = 0; i < nRanges; ++i )

{

GridRangeInfo r = rangeList[0];

int bottom = r.Bottom;

for(int j = 1; j < rangeList.Count; ++j)

{

if(rangeList[j].Bottom > bottom)

{

r = rangeList[j];

bottom = r.Bottom;

}

}

rangeList.Remove(r);

this.gridDataBoundGrid1.Binder.RemoveRecords(r.Top - 1, r.Bottom - 1);

}

e.Cancel = true;

}

indeleting = false;

}

}

VB

Private indeleting As Boolean = False

Private Sub gridDataBoundGrid1_RowsDeleting(ByVal sender As Object, ByVal e As

Syncfusion.Windows.Forms.Grid.GridRowRangeEventArgs) Handles gridDataBoundGrid1.RowsDeleting

If (Not indeleting) Then

indeleting = True

Dim rangeList As GridRangeInfoList = Me.gridDataBoundGrid1.Selections.GetSelectedRows(True, False)

If rangeList.Count > 1 Then

Me.gridDataBoundGrid1.Selections.Clear()

Dim nRanges As Integer = rangeList.Count

Dim i As Integer = 0

Do While i < nRanges

Dim r As GridRangeInfo = rangeList(0)

Dim bottom As Integer = r.Bottom

Dim j As Integer = 1

Do While j < rangeList.Count

If rangeList(j).Bottom > bottom Then

r = rangeList(j)

bottom = r.Bottom

End If

j += 1

Loop

rangeList.Remove(r)

Me.gridDataBoundGrid1.Binder.RemoveRecords(r.Top - 1, r.Bottom - 1)

i += 1

Loop

e.Cancel = True

End If

indeleting = False

End If

End Sub

Here is the link with both CS and VB samples: http://websamples.syncfusion.com/samples/kb/grid.windows/GDBGDeleteRanges/main.htm

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

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