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 get the cellvalue when right click the cell in GridDataBoundGrid?

Platform: WinForms |
Control: GridDataBoundGrid(Classic)

In order to get the cell value, row index and column index of a cell while right click, the CellClick and MouseDown events can be used. In that events, mouse click is validated whether it is right click by using Button property of MouseEventArgs.

Code Snippet

Using CellClick event

C#

this.gridDataBoundGrid1.CellClick += gridDataBoundGrid1_CellClick;
 
void gridDataBoundGrid1_CellClick(object sender, GridCellClickEventArgs e)
{
   if(e.MouseEventArgs.Button==System.Windows.Forms.MouseButtons.Right)
   {
      int col = e.ColIndex;
      int row = e.RowIndex;
      object value = this.gridDataBoundGrid1.Model[row, col].CellValue;
      Console.WriteLine("RowIndex:" + row + "\n" + "ColumnIndex:" + col + "\n" + "CellValue:" + value);
   }
}

 

VB

AddHandler Me.gridDataBoundGrid1.CellClick, AddressOf gridDataBoundGrid1_CellClick
 
Private Sub gridDataBoundGrid1_CellClick(ByVal sender As Object, ByVal e As GridCellClickEventArgs)
   If e.MouseEventArgs.Button=System.Windows.Forms.MouseButtons.Right Then
   Dim col As Integer = e.ColIndex
   Dim row As Integer = e.RowIndex
   Dim value As Object = Me.gridDataBoundGrid1.Model(row, col).CellValue
   Console.WriteLine("RowIndex:" & row + Constants.vbLf & "ColumnIndex:" & col + Constants.vbLf & "CellValue:" & value)
   End If
End Sub

 

Using MouseDown event

C#

this.gridDataBoundGrid1.MouseDown += gridDataBoundGrid1_MouseDown;
 
void gridDataBoundGrid1_MouseDown(object sender, MouseEventArgs e)
{
   if(e.Button==System.Windows.Forms.MouseButtons.Right)
   {
      int col = this.gridDataBoundGrid1.CurrentCell.ColIndex;
      int row = this.gridDataBoundGrid1.CurrentCell.RowIndex;
      object value = this.gridDataBoundGrid1.Model[row, col].CellValue;
      Console.WriteLine("RowIndex:" + row + "\n" + "ColumnIndex:" + col + "\n" + "CellValue:" + value);
      }
}

 

VB

AddHandler Me.gridDataBoundGrid1.MouseDown, AddressOf gridDataBoundGrid1_MouseDown
 
Private Sub gridDataBoundGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
   If e.Button=System.Windows.Forms.MouseButtons.Right Then
   Dim col As Integer = Me.gridDataBoundGrid1.CurrentCell.ColIndex
   Dim row As Integer = Me.gridDataBoundGrid1.CurrentCell.RowIndex
   Dim value As Object = Me.gridDataBoundGrid1.Model(row, col).CellValue
   Console.WriteLine("RowIndex:" & row + Constants.vbLf & "ColumnIndex:" & col + Constants.vbLf & "CellValue:" & value)
   End If
End Sub

 

 

 

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