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

Looping table Elements

Hi, in my current program i am looping all elements searching for GridNestedTables with the following code: foreach (Element em in m_syncGrid.Table.Elements) { if (em is GridNestedTable) { ... this works fine. After looping all elements i am looping all gridgroupingControl1.Table.Records. Now i''m wondering if i could get a reference to each record when looping the elements ?? I want to avoid looping the grid twice. If you could tell me what i would have to cast the element to would be great. I already tried record and others but either i don''t get any hit or the element cannot be casted in a usable manner. Thanks

1 Reply

AD Administrator Syncfusion Team April 13, 2005 06:44 PM

If you want to get at the recrods in a GriNestedTable, you need to drill down until there is no longer a gridnestedtable as the element being looked at.
int i = 0;
foreach(Element el in this.gridGroupingControl1.Table.Elements)
{
	Console.WriteLine("{0}-{1}", i, el.GetType());
	i += 1;

	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;
			}
			foreach(GridRecord r in gnt.ChildTable.ParentTable.Records)
			{
				DataRowView drv = r.GetData() as DataRowView;
				if(drv != null)
					Console.WriteLine(drv[1].ToString()); //show column 2
			}
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon