Articles in this section
Category / Section

How to get the cellvalue when right click the cell in GridDataBoundGrid?

1 min read

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

 

 

 

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