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.
Unfortunately, activation email could not send to your email. Please try again.

How to get all the underlying data rows when a pivoted row is selected?

Thread ID:

Created:

Updated:

Platform:

Replies:

99947 Jun 21,2011 11:26 PM Jun 22,2011 05:09 AM Windows Forms 1
loading
Tags: GridControl
Nihar Ranjan Dalai
Asked On June 21, 2011 11:26 PM

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.


Jisha Joy [Syncfusion]
Replied On June 22, 2011 05:09 AM

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 GetUnderlyingDataFromSelectedRows(PivotGridLibrary.PivotGridControl grid, PivotGridLibrary.PivotSchema schema)
{
List list = new List();
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());
}
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



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.

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.

;