Articles in this section
Category / Section

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

1 min read

 

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied