Articles in this section
Category / Section

How to get the current cell of the nested ChildTable in WinForms GridGroupingControl?

3 mins read

Show record and column name

The usual TableControl.CurrentCell property does not give the exact CurrentCell when the CurrentCell is in the nested table. To get the CurrentCell value from the nested tables, you can use the following methods:

1. By using GetNestedCurrentCell()

2. By using CurrentElement.

By using the GetNestedCurrentCell():

By using the GetNestedCurrentCell(), you get the CurrentCell directly from anywhere in the nested table. Refer to the following code to get the CurrentCell.

C#

//Gets the CurrentCell by using the GetNestedCurrentCell().
GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell();

VB

'Gets the CurrentCell by using the GetNestedCurrentCell() .
Dim cc As GridCurrentCell = Me.gridGroupingControl1.TableControl.GetNestedCurrentCell()

By using the CurrentElement:

By using the Table and TableControl properties of the GridGroupingControl that is taken from the CurrentElement, you can get the CurrentCell even when it is in the child table.  Refer to the following code to get the CurrentCell.

C#

void btnGetrecord_Click(object sender, EventArgs e)
{
    //Gets the Current Element.
    Element el = this.gridGroupingControl1.Table.GetInnerMostCurrentElement();
    if (el != null)
    {
        //Gets table from element parenttable.
        GridTable table = el.ParentTable as GridTable;
        //Gets table control by using the table descriptor name. 
        GridTableControl tableControl = this.gridGroupingControl1.GetTableControl (table.TableDescriptor.Name);
        //Gets current cell by using the tablecontrol.
        GridCurrentCell cc = tableControl.CurrentCell;
        Console.WriteLine("Row Column indes by using Currrentelement");
        Console.WriteLine("Row Index"+ cc.RowIndex.ToString());
        Console.WriteLine("Column Index"+ cc.ColIndex.ToString());
    }
}

VB

Private Sub btnGetrecord_Click(ByVal sender As Object, ByVal e As EventArgs)
   'Gets the Current Element.
   Dim el As Element = Me.gridGroupingControl1.Table.GetInnerMostCurrentElement()
   If el IsNot Nothing Then
      'Gets table from element parenttable.
      Dim table As GridTable = TryCast(el.ParentTable, GridTable)
      'Gets table control by using the table descriptor name. 
      Dim tableControl As GridTableControl = Me.gridGroupingControl1.GetTableControl (table.TableDescriptor.Name)
      'Gets current cell by using tablecontrol.
      Dim cc As GridCurrentCell = tableControl.CurrentCell
      Console.WriteLine("Row Column indes by using Currrentelement")
      Console.WriteLine("Row Index" & cc.RowIndex.ToString())
      Console.WriteLine("Column Index" & cc.ColIndex.ToString())
   End If
End Sub

The following screenshots display Record and Column name displayed on button click.

Show record and column name

Samples:

C#: RecordandColumnname-C#

VB: RecordandColumnname-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