How can I get the record and column of the current cell when I have nested tables in GridGroupingControl?
(Views :2272)

To get the record and column of the current cell, we need to access the CurrentElement. Using the Table and TableControl properties of the GridGroupingControl we can get the CurrentCell even if it is in the child table. With the CurrentCell, we can get the RowIndex and ColumnIndex, through which we could get the style info of the currentcell and currentrecord and the column name.

C#
private void button1_Click(object sender, System.EventArgs e)
{
Element el = this.gridGroupingControl1.Table.GetInnerMostCurrentElement();
if(el != null)
{
GridTable table = el.ParentTable as GridTable;
GridTableControl tableControl = this.gridGroupingControl1.GetTableControl(table.TableDescriptor.Name);
GridCurrentCell cc = tableControl.CurrentCell;
GridTableCellStyleInfo style = table.GetTableCellStyle(cc.RowIndex, cc.ColIndex);
GridRecord rec = el as GridRecord;
if(rec == null && el is GridRecordRow)
{
rec = el.ParentRecord as GridRecord;
}
if(rec != null)
{
Console.WriteLine(style.TableCellIdentity.Column.Name);
Console.WriteLine(rec.GetValue(style.TableCellIdentity.Column.Name));
}
}
}
VB
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Dim el As Element = Me.gridGroupingControl1.Table.GetInnerMostCurrentElement()
If Not el Is Nothing Then
Dim table As GridTable = CType(IIf(TypeOf el.ParentTable Is GridTable, el.ParentTable, Nothing), GridTable)
Dim tableControl As GridTableControl = Me.gridGroupingControl1.GetTableControl(table.TableDescriptor.Name)
Dim cc As GridCurrentCell = tableControl.CurrentCell
Dim style As GridTableCellStyleInfo = table.GetTableCellStyle(cc.RowIndex, cc.ColIndex)
Dim rec As GridRecord = CType(IIf(TypeOf el Is GridRecord, el, Nothing), GridRecord)
If rec Is Nothing AndAlso TypeOf el Is GridRecordRow Then
rec = CType(IIf(TypeOf el.ParentRecord Is GridRecord, el.ParentRecord, Nothing), GridRecord)
End If
If Not rec Is Nothing Then
Console.WriteLine(style.TableCellIdentity.Column.Name)
Console.WriteLine(rec.GetValue(style.TableCellIdentity.Column.Name))
End If
End If
End Sub

Sample:

http://websamples.syncfusion.com/samples/kb/grid.windows/GGCColumnName/main.htm

::adCenter::