This is a migrated thread and some comments may be shown as answers.

How to get PivotGridRowHeaderCell parent

4 Answers 81 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Barbaros Saglamtimur
Top achievements
Rank 1
Barbaros Saglamtimur asked on 03 May 2013, 09:34 AM
Hi,

I would like get  PivotGridRowHeaderCell's parent in CellDataBound event. For visual explanation see attached image.

TIA

4 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 08 May 2013, 07:53 AM
Hello,

This is achievable by obtaining a reference to the ParentIndexes collection of the PivotGridRowHeaderCell. It returns an array of the names of parent fields of a given header cell.

Regards,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Barbaros Saglamtimur
Top achievements
Rank 1
answered on 15 May 2013, 07:05 AM
Thanks for your reply,
I already found it, but ParentIndexes returns array of DataItems, I need field properties as-well. So List<PivotGridCell> would be super.
0
Angel Petrov
Telerik team
answered on 20 May 2013, 06:06 AM
Hi Barbaros,

I am sorry to say but with the current implementation of the control returning a list of PivotGridCells is not possible. What you can do is access the field like demonstrated in the code snippet below:
protected void RadPivotGrid2_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
    {
        if (e.Cell is PivotGridRowHeaderCell)
        {
            PivotGridRowHeaderCell cell = e.Cell as PivotGridRowHeaderCell;
            List<PivotGridField> rowFields = RadPivotGrid2.Fields.Where(x=>x is PivotGridRowField).ToList();
            rowFields.OrderBy(x => x.ZoneIndex);
            int index=rowFields.IndexOf(cell.Field);
            PivotGridField field = rowFields[index - 1];
        }
    }


All the best,
Angel Petrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Barbaros Saglamtimur
Top achievements
Rank 1
answered on 20 May 2013, 07:49 AM
Thanks for your reply. I have already achieved my goal with the following code ( on CellDataBound event)
if (e.Cell is PivotGridRowHeaderCell)
{
                    var parents = ((PivotGridHeaderCell)(e.Cell)).ParentIndexes;
                    Dictionary<int, string> theParentsDict = new Dictionary<int, string>();
                    Dictionary<int, PivotGridField> theFieldsDict = new Dictionary<int, PivotGridField>();
                    theParentsDict =
                        parents.Select((p, index) => new {Index = index, DataItem = p})
                               .ToDictionary(k => k.Index, v => v.DataItem.ToString());
                    theFieldsDict =
                        RadPivotGrid1.Fields.GetFieldsByType("PivotGridRowField")
                                     .Where(f => !f.IsHidden)
                                     .Select(f=> new {Index = f.ZoneIndex, DataField = f})
                                     .ToDictionary(k => k.Index, v => v.DataField);
                    Dictionary<int, PivotGridField> rowItems = (from p in theParentsDict
                                                          join f in theFieldsDict
                                                              on p.Key equals f.Key
                                                                select new
                                                          {
                                                              Index = p.Key,
                                                              RowField = f.Value,
                                                          }).ToDictionary(k => k.Index, v => v.RowField);
}
Tags
PivotGrid
Asked by
Barbaros Saglamtimur
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Barbaros Saglamtimur
Top achievements
Rank 1
Share this question
or