Articles in this section
Category / Section

How to retrieve current record on cell double click in WinForms GridGroupingControl?

2 mins read

CellDoubleClick event

The TableControlCellDoubleClick/TableControl.CellDoubleClick event can be used to notify whenever the double click on a cell is occurred. For further information about the event, TableControlCellDoubleClick .

 

In order to retrieve the current selected record when the cell double click is occurred, the SelectedRecords collection can be used to retrieved record and this can be available from the TableControl of the event args. To get the values of particular column, the GetValue() method of the record can be used.

 

Using TableControlCellDoubleClick event

C#

//Event triggering
this.gridGroupingControl1.TableControlCellDoubleClick += GridGroupingControl1_TableControlCellDoubleClick;
 
//Event customization
private void GridGroupingControl1_TableControlCellDoubleClick(object sender, GridTableControlCellClickEventArgs e)
{
    if (e.TableControl.Table.SelectedRecords.Count > 0)
    {
        Record selectedRecord;
        if (gridGroupingControl1.TableOptions.ListBoxSelectionMode == SelectionMode.One)
        {
            //To get the selected record when selection mode is one
            selectedRecord = e.TableControl.Table.SelectedRecords[0].Record;
        }
        else
        {
            //To get the selected record for other selection modes
            int count = e.TableControl.Table.SelectedRecords.Count;
            selectedRecord = e.TableControl.Table.SelectedRecords[count - 1].Record;
        }
        //To show the new form
        DisplayForm displayForm = new DisplayForm(selectedRecord);
        displayForm.Show();
    }
}

 

VB

'Event triggering
AddHandler Me.gridGroupingControl1.TableControlCellDoubleClick, AddressOf GridGroupingControl1_TableControlCellDoubleClick
 
Private Sub GridGroupingControl1_TableControlCellDoubleClick(ByVal sender As Object, ByVal e As GridTableControlCellClickEventArgs)
 If e.TableControl.Table.SelectedRecords.Count > 0 Then
  Dim selectedRecord As Record
        If gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One Then
            'To get the selected record when selection mode Is one
            selectedRecord = e.TableControl.Table.SelectedRecords(0).Record
        Else
            'To get the selected record for other selection modes
            Dim count As Integer = e.TableControl.Table.SelectedRecords.Count
            selectedRecord = e.TableControl.Table.SelectedRecords(count - 1).Record
        End If
        'To show the New form
        Dim displayForm As New DisplayForm(selectedRecord)
  displayForm.Show()
 End If
End Sub

 

Using TableControl.CellDoubleClick event

C#

//Event triggering
this.gridGroupingControl1.TableControl.CellDoubleClick += TableControl_CellDoubleClick;
 
//Event customization
private void TableControl_CellDoubleClick(object sender, GridCellClickEventArgs e)
{
    if (e.TableControl.Table.SelectedRecords.Count > 0)
    {
        Record selectedRecord;
        if (gridGroupingControl1.TableOptions.ListBoxSelectionMode == SelectionMode.One)
        {
            //To get the selected record when selection mode is one
            selectedRecord = gridGroupingControl1.Table.SelectedRecords[0].Record;
        }
        else
        {
            //To get the selected record for other selection modes
            int count = gridGroupingControl1.Table.SelectedRecords.Count;
            selectedRecord = gridGroupingControl1.Table.SelectedRecords[count - 1].Record;
        }
        //To show the new form
        DisplayForm displayForm = new DisplayForm(selectedRecord);
        displayForm.Show();
    }
}

 

VB

'Event triggering
AddHandler Me.gridGroupingControl1.TableControl.CellDoubleClick, AddressOf TableControl_CellDoubleClick
 
'Event customization
Private Sub TableControl_CellDoubleClick (ByVal sender As Object, ByVal e As GridCellClickEventArgs)
If e.TableControl.Table.SelectedRecords.Count > 0 Then
  Dim selectedRecord As Record
        If gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One Then
            'To get the selected record when selection mode Is one
            selectedRecord = gridGroupingControl1.Table.SelectedRecords(0).Record
        Else
            'To get the selected record for other selection modes
            Dim count As Integer gridGroupingControl1.Table.SelectedRecords.Count
            selectedRecord = gridGroupingControl1.Table.SelectedRecords(count - 1).Record
        End If
        'To show the New form
        Dim displayForm As New DisplayForm(selectedRecord)
  displayForm.Show()
 End If
End Sub

 

Screenshot

Shows the order details while double click on a cell

 

Samples:

C#: RecordOnCellDoubleClick_CS

VB: RecordOnCellDoubleClick_VB

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