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 to get all the underlying data rows when a pivoted row is selected?

Hi,

I have a pivot grid which is pivoted about 2 row fields. I have set the ListBoxSelectionMode to MultiExtended. Now when I select a particular pivoted row, I wish to be able to get all the underlying data rows (i.e. all data rows that make up the pivoted row and not the row displayed on the grid).

How can I achieve this?

Thanks and regards,
Nihar.


1 Reply

JJ Jisha Joy Syncfusion Team June 22, 2011 09:09 AM UTC

Hi Nihar,

Please refer to the following,

1)To Hide the row headers, you can set the rowheader column width to zero with code like this:

//take care of topleft
Color color2 = Color.FromArgb(120, Color.LightGreen);
pivotGrid.MainDisplayGrid.CoveredRanges.Add(GridRangeInfo.Cells(1, 1, 1, 2));
pivotGrid.MainDisplayGrid.Model.Options.ListBoxSelectionMode = SelectionMode.MultiExtended;
pivotGrid.MainDisplayGrid[2, 1].BackColor = color2;
pivotGrid.MainDisplayGrid.Rows.FrozenCount = 2;
pivotGrid.MainDisplayGrid.Model.Options.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;
pivotGrid.MainDisplayGrid.Model.ColWidths[0] = 0;


2) Here is a method that you can add to your code to get the underlying data for the selected rows in the pivot grid.


public List<object> GetUnderlyingDataFromSelectedRows(PivotGridLibrary.PivotGridControl grid, PivotGridLibrary.PivotSchema schema)
{
List<object> list = new List<object>();
GridRangeInfoList selectedRanges = grid.MainDisplayGrid.Selections.Ranges;
if (selectedRanges.Count == 0)
return list;

List> keySets = new List>();

foreach (GridRangeInfo range in selectedRanges)
{
GridRangeInfo r = range.ExpandRange(1, 1, grid.MainDisplayGrid.RowCount, grid.MainDisplayGrid.ColCount);
Dictionary keySet = new Dictionary();
for (int row = r.Top; row <= r.Bottom; row)
{
int col = 1;
foreach (string s in schema.RowFields)
{
GridRangeInfo r1 = grid.MainDisplayGrid.CoveredRanges.FindRange(row, col);
if(r1.IsEmpty)
r1 = GridRangeInfo.Cell(row, col);
if (r1.Left != col)
{
break;
}
if (!keySet.ContainsKey(s))
{
keySet.Add(s, new List<object>());
}
if (!keySet[s].Contains(grid.MainDisplayGrid[r1.Top, r1.Left].CellValue))
{
keySet[s].Add(grid.MainDisplayGrid[r1.Top, r1.Left].CellValue);
}

col ;

}
}
keySets.Add(keySet);
}

ITypedList data = grid.DataSource as ITypedList;
PropertyDescriptorCollection pdc = data.GetItemProperties(null);
foreach (object o in (IList)data)
{
foreach (Dictionary> keySet in keySets)
{
bool ok = true;

foreach (string name in keySet.Keys)
{
string val = pdc[name].GetValue(o).ToString();
ok = keySet[name].IndexOf(val) > -1;
if (!ok)
break;
}
if (ok)
list.Add(o);
}
}

return list;
}
}


Please let me know if this helps.

Regards,
Jisha




Loader.
Live Chat Icon For mobile
Up arrow icon