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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I retrieve the current cell value in GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

13296 Apr 25,2004 11:53 PM UTC May 13,2004 11:36 AM UTC WinForms 6
loading
Tags: GridControl
oktave
Asked On April 25, 2004 11:53 PM UTC

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?

Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On 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);

Administrator [Syncfusion]
Replied On May 13, 2004 07:27 AM UTC

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

Administrator [Syncfusion]
Replied On 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
		}
	}
}

Administrator [Syncfusion]
Replied On May 13, 2004 09:02 AM UTC

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

Administrator [Syncfusion]
Replied On 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);
		}
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;