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

How can I retrieve the current cell value in GridGroupingControl

Hi, I try to get the current cell value in a GridGroupingControl. How can I do this? GridGroupingControl is a little bit different from GridControl and GridDataBoundControl, right?

6 Replies

AD Administrator Syncfusion Team April 26, 2004 11:17 AM UTC

You can get the current record with Record r = groupingGrid.Table.CurrentRecord the record object provides methods to get values, e.g. r.GetValue("CustomerID"). You can also get the underlying DataRow when you call r.GetData(). That will return the DataRowView element for the record. You can get at the currentcell using gridGroupingControl1.TableControl.CurrentCell.


AD Administrator Syncfusion Team April 26, 2004 11:27 AM UTC

Here is code to get the value in a flat grouping grid. Record r = gridGroupingControl1.Table.CurrentRecord; int col = this.gridGroupingControl1.TableControl.CurrentCell.ColIndex; int field = this.gridGroupingControl1.TableDescriptor.ColIndexToField(col); object o = r.GetValue(this.gridGroupingControl1.TableDescriptor.Fields[field]); Console.WriteLine(o);


AD Administrator Syncfusion Team May 13, 2004 07:27 AM UTC

But if current cell belongs to nested table?... This way works for parent table only.


AD Administrator Syncfusion Team May 13, 2004 08:09 AM UTC

You have to walk down the parent-child table chain to find the proper parent table.
private void button1_Click(object sender, System.EventArgs e)
{
	Element el = this.gridGroupingControl1.TableControl.Table.CurrentElement;
	if(el != null)
	{
		if(el is GridRecord)
		{
			DataRowView drv = (el as Record).GetData() as DataRowView;
			Console.WriteLine(drv[1].ToString()); //show column 2
		}
		else if(el is GridNestedTable)
		{
			GridNestedTable gnt = el as GridNestedTable;
			GridNestedTable gnt1 = gnt;
			while(gnt1 != null && gnt1.ChildTable != null)
			{
				gnt = gnt1;
				gnt1 = gnt.ChildTable.ParentTable.CurrentElement as GridNestedTable;
			}
			DataRowView drv = gnt.ChildTable.ParentTable.CurrentElement.GetData() as DataRowView;
			if(drv != null)
				Console.WriteLine(drv[1].ToString()); //show column 2
		}
	}
}


AD Administrator Syncfusion Team May 13, 2004 09:02 AM UTC

Console.WriteLine(drv[1].ToString()); //show column 2 And how to access to CURRENT CELL here ?


AD Administrator Syncfusion Team May 13, 2004 11:36 AM UTC

Once you have the nested table, you can use it to get the associated TableControl. From the tableControl, you can use the same code as above to access the currentcell in that TableControl.
private void button1_Click(object sender, System.EventArgs e)
{
	Element el = this.gridGroupingControl1.TableControl.Table.CurrentElement;
	if(el != null)
	{
		if(el is GridRecord)
		{
			Record r = el as Record;
			int col = this.gridGroupingControl1.TableControl.CurrentCell.ColIndex;
			int field = this.gridGroupingControl1.TableDescriptor.ColIndexToField(col);
			object o = r.GetValue(this.gridGroupingControl1.TableDescriptor.Fields[field]);
			Console.WriteLine(o);
		}
		else if(el is GridNestedTable)
		{
			GridNestedTable gnt = el as GridNestedTable;
			GridNestedTable gnt1 = gnt;
			while(gnt1 != null && gnt1.ChildTable != null)
			{
				gnt = gnt1;
				gnt1 = gnt.ChildTable.ParentTable.CurrentElement as GridNestedTable;
			}
			Record r = gnt.ChildTable.ParentTable.CurrentRecord;
			string name = gnt.ChildTable.ParentTable.TableDescriptor.Name;
			GridTableControl tableControl = this.gridGroupingControl1.GetTableControl(name);
			int col = tableControl.CurrentCell.ColIndex;
			int field = gnt.ChildTable.ParentTable.TableDescriptor.ColIndexToField(col);
			object o = r.GetValue(gnt.ChildTable.ParentTable.TableDescriptor.Fields[field]);
			Console.WriteLine(o);
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon