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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to deselect the rows in the grid programmatically?

Platform: WinForms |
Control: GridDataBoundGrid(Classic)
Tags: selection

In GridDataBoundGrid selection can be cleared by using Selection.Clear() method. The Clear method of ranges is used to remove the collection along from the Ranges collection where the Selection.Clear() is used to remove all selection from Grid.

private void button1_Click(object sender, EventArgs e)
{
    this.gridDataBoundGrid1.SortColumn(1);
 
    // To Remove the selection from Grid
    this.gridDataBoundGrid1.Selections.Clear();
} 

 

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
 Me.gridDataBoundGrid1.SortColumn(1)
 
 ' To Remove the selection from Grid
 Me.gridDataBoundGrid1.Selections.Clear()
End Sub

 

While sorting the column using cell click on header cell, Current cell is moved to first cell if grid doesn’t has any current cell. Due to this, selection also moved to the first row. You can avoid this issue by using CurrentCellMoving event.

 

this.gridDataBoundGrid1.CurrentCellMoving += gridDataBoundGrid1_CurrentCellMoving;

 

void gridDataBoundGrid1_CurrentCellMoving(object sender, GridCurrentCellMovingEventArgs e)

{

    if (e.RowIndex == 1)

    {

        e.Cancel = true;

    }

}

 

Private Me.gridDataBoundGrid1.CurrentCellMoving += AddressOf gridDataBoundGrid1_CurrentCellMoving
 
Private Sub gridDataBoundGrid1_CurrentCellMoving(ByVal sender As Object, ByVal e As GridCurrentCellMovingEventArgs)
 If e.RowIndex = 1 Then
  e.Cancel = True
 End If
End Sub

 

Sample

GridDataBoundGridSelection_C#

GridDataBoundGridSelection_VB

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.

Up arrow icon

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

Live Chat Icon For mobile