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
close icon

Retrieving the Group a Cell belongs to

I might be missing something obvious but I am trying to figure out how to retrieve the group that a cell belongs to within my QueryCellStyleInfo event. For example if I am on a caption row, I could get the ParentGroup no problem: ((CaptionRow) e.TableCellIdentity.DisplayElement).ParentGroup However I do not know how to get the current group that the current cell belongs to. Do I have to cast something into a Group object? Thanks, Erlly

7 Replies

AD Administrator Syncfusion Team October 26, 2004 12:12 PM UTC

Does this code give you what you want? It colors any checbox cell blue if its parent group has 2 children. (If you want the records in the group, then grp.Records in the code below).
private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
	if(e.Style.CellType == "CheckBox")
	{
		GridRecordRow rec = this.gridGroupingControl1.Table.DisplayElements[e.TableCellIdentity.RowIndex] as GridRecordRow;
		if(rec != null)
		{
			Group grp = rec.ParentGroup;
			if(grp != null && grp.GetChildCount() == 2)
			{
				e.Style.BackColor = Color.Blue;
			}
		}
	}
}


EB Erlly Bayuelo October 26, 2004 01:49 PM UTC

I could see if the DisplayElement is a record how the ParentGroup property yields the group the cell belongs to. However, how about if the DisplayElement is a CaptionRow ? Lets say that I am grouping by CarType and then Make so I have: All Sedans BMW Sedans: 2 5 Series 3 Series Ford Sedans: 2 Focus Taurus SUV BWM Trucks: 1 X5 Lets say I just expanded Sedans so QueryCellInfo fires for the group caption row "BMW Sedans:2" then how do I get a handle to the BWM Sedans Group. Wouldnt the ParentGroup of the "BMW Sedans" caption row be "All Sedans" [I do not want a handle to "All Sedans"]. The sample you gave me works if I am on the 5 series detail level record and want a handle to BMW Sedans but still does not clarify the situation if I am at a group caption row. Thanks, Erlly


AD Administrator Syncfusion Team October 26, 2004 09:22 PM UTC

Here is little sample that displays information from the first record in a group as part of the Caption row using QueryCellStyleInfo. Is this the information you need? GGC_790.zip


EB Erlly Bayuelo October 27, 2004 02:12 AM UTC

Looking at the sample it leads me to believe that the Parent Group of a Caption Row is really just that same group the caption is describing. My confusion was that I thought the Parent Group of a Caption Row was a located a grouping level above the caption. Again, what you seem to be saying is that the parent group of a caption row is the same Group object as the parent group of the detail records that caption is describing.


AD Administrator Syncfusion Team October 27, 2004 05:45 AM UTC

To get at the ''contents'' of a group given the CaptionRow, you get teh CaptionRow''s parent group and then check the Details collection of this group. The details will either be records or child groups dependng what group level the CaptionRow is from. Here is a snippet that you can add to the QueryCellStyleInfo handler in the previous sample to show this information when you expand a "Col1" group in the sample.
Group grp = gcr.ParentGroup; //gcr is GridCaptionRow
if(grp.IsExpanded)
{
	Console.WriteLine("++++++++");
	DetailsSection ds = grp.Details;
	if(ds is GridRecordsDetails)
	{
		GridRecordsDetails grd = ds as GridRecordsDetails;
		foreach(Record r2 in grd.Records)
		{
			Console.WriteLine("*  " + r2.ToString());
		}
	}
	else if(ds is GridGroupsDetails)
	{
		GridGroupsDetails ggd = ds as GridGroupsDetails;
		foreach(Group g in ggd.Groups)
		{
			Console.WriteLine("+  " + g.ToString());
		}
	}
	Console.WriteLine("-------");
}


EB Erlly Bayuelo October 27, 2004 10:49 AM UTC

Thanks a lot Clay. Your examples and code snippets made it pretty clear. I think I pretty much got it now. And I guess that once I got the CaptionRow''s ParentGroup I could always navigate up to higher level groups (i.e. lower GroupLevel values) by just using Group.ParentGroup recursively, right.


AD Administrator Syncfusion Team October 28, 2004 04:32 AM UTC

Yes. You can use code such as this to step back up through the nested groups.
Group grp = gcr.ParentGroup; //gcr is GridCaptionRow
string spc = new string(''*'', 20); //for indents
while(grp != null)
{
	Console.WriteLine(spc + grp.ToString());
	spc = spc.Substring(0, spc.Length - 2);
	grp = grp.ParentGroup;
}

Loader.
Live Chat Icon For mobile
Up arrow icon