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

GridControl Remove Selected Rows

Thread ID:





95206 Jun 25,2010 03:36 PM UTC Sep 14,2018 09:09 AM UTC WinForms 8
Tags: GridControl
Nathaniel Felt
Asked On June 25, 2010 03:36 PM UTC

Is there a simple way to remove the selected rows in a GridControl?

Any help is appreciated.

Jisha Joy [Syncfusion]
Replied On June 28, 2010 07:09 AM UTC

Hi Nathaniel,

You could use the Rows.RemoveRange to remove the selected row ranges in GridControl. See the code:

GridRangeInfo r= this.gridControl1.Selections.Ranges.ActiveRange;

this.gridControl1.Rows.RemoveRange(r.Top - 1, r.Bottom - 1);


Nathaniel Felt
Replied On July 12, 2010 05:20 PM UTC


Your example works well when only one item is selected or a sequential range is selected, but not if there are multiple non-sequential selections (ie rows 1, 3, and 10).

Do you have a sample that would work for this particular case?

Thank you.

Nathaniel Felt
Replied On July 12, 2010 05:32 PM UTC


I found the information I needed. For anyone else looking to do something similar:


Dim range as GridRangeInfoList = GridControl1.Selections.Ranges

If range IsNot Nothing Then
For i = (range.Count -1) To 0 Step -1
End If

Jisha Joy [Syncfusion]
Replied On July 13, 2010 05:55 AM UTC

Hi Nathaniel,

Thank you for your update.


Adam Bruss
Replied On June 15, 2016 12:23 PM UTC

The solution in Nathaniel's last comment for removing multiple gridrangeinfos does not work for me. What is the proper way to remove all the GridRangeInfos in a GridRangeInfoList? Removing one gridrangeinfo in the list seems to alter the list so the next time you go through the loop the list is empty.

Amresh S [Syncfusion]
Replied On June 16, 2016 09:17 AM UTC

Hi Adam, 
Thank you for using Syncfusion products. 
In order to remove a selected row from the grid, you can use the RemoveRange() method via the Rows property. Then, the grid updates the cells with the removed row values. Please make use of the following code snippet to remove the selected range of rows and the attached sample. 
// Trigger the required event. 
this.button1.Click += new System.EventHandler(this.button1_Click); 
private void button1_Click(object sender, EventArgs e) 
     GridRangeInfo ranges = this.gridControl1.Selections.Ranges.ActiveRange; 
     this.gridControl1.Rows.RemoveRange(ranges.Top, ranges.Bottom); 
Amresh S.

Replied On September 13, 2018 07:01 PM UTC

That solution is still not working for me. I have solved it this way.
By iterating the grid in reverse order.
I first clear the cells, I am iterating through a grid to move selected rows to a second grid and clearing the rows in that foreach loop using: 

this.gridControl1.ClearCells(GridRangeInfo.Row(x), true);

when that loop is done, I do another for loop starting at the largest row value to the first row
In this loop I look for a blank entry, like this:

  for (int i = this.gridControl1.RowCount; i > 0; i--)
                if (gridControl1[i, 2].Text.Length == 0)
                    this.gridControl1.Rows.RemoveRange(i, i);

You cant delete the rows in a for each loop because you get a collections modified error
In the for next loop, when you delete a row the number of rows (RowCount) is reduced by 1
If you did the loop from row 1 to the bottom, deleting row 1 causes row 2 to become row 1
if row 1 now has a length of 0 in the cell your loop skips over it.

For large grids, you could use a list and save the row numbers when clearing cells in the foreach loop
to save time when actually deleting them again going from highest to lowest row

Here is my  foreach loop: It copies grid 1 selections to grid 2, erases cell data without deleting the rows

          int r = NextAvailableRow(); // A method to search for an empty row checks cell length.
          int x = 0;
           foreach (GridRangeInfo range in this.gridControl1.Selections.Ranges)
                Int32.TryParse(range.Info.ToString().Substring(1), out x);
                this.gridControl2[r, 2].Text = this.gridControl1[x, 1].Text;
                this.gridControl1.ClearCells(GridRangeInfo.Row(x), true);

Mohanraj Gunasekaran [Syncfusion]
Replied On September 14, 2018 09:09 AM UTC

Hi Mark, 

Thanks for your update. 
Yes, you can delete the rows in reverse order to avoid the collection modified error. Also, you can use the following solution to delete the selected ranges, 

To delete the dynamically selected rows you could use the RemoveRange method with cloneable object of SelectedRanges. Please refer the following code example, 

Code example 
GridRangeInfoList rangeList = this.gridControl1.Model.SelectedRanges.Clone(); 
foreach (GridRangeInfo range in rangeList) 
    this.gridControl1.Rows.RemoveRange(range.Top, range.Bottom); 
To avoid the empty row generating while pressing the delete key, you could handle the KeyDown event while pressing the delete key. Please refer the following code example, 

Code example 
this.gridControl1.KeyDown += GridControl1_KeyDown; 
private void GridControl1_KeyDown(object sender, KeyEventArgs e) 
    if (e.KeyData == Keys.Delete) 
        GridRangeInfoList rangeList = this.gridControl1.Model.SelectedRanges.Clone(); 
        foreach (GridRangeInfo range in rangeList) 
            this.gridControl1.Rows.RemoveRange(range.Top, range.Bottom); 
        e.Handled = true; 
Please let us know if you have any concerns. 

Mohanraj G 


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.

Please sign in to access our forum

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