Image 1 is the data I have to start with
Image 2 is how I need the data to be formatted.
Just pivoting this data is out of the question as it does not do what I need it to do.
I have tried to use band.Groups, but I can't get it to work and the example provided here http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.3~Infragistics.Win.UltraWinGrid.UltraGridGroup.html doesn't show me how to add multiple groups to a group
any help would be much appreciated
Below is the code that I used to get it working, it was more of a data formatting issue than anything
ultraGrid.DisplayLayout.Bands[0].RowLayoutStyle = RowLayoutStyle.GroupLayout; ultraGrid.DisplayLayout.Override.AllowRowLayoutColMoving = Infragistics.Win.Layout.GridBagLayoutAllowMoving.AllowAll; ultraGrid.DisplayLayout.Bands[0].Groups.Clear();
DataTable dt = UltraGridMethods.CreateDataTableFromAllRowsAndAllColumnsInUltraGrid(ultraGrid);
List<string> listGroupingColumns = new List<string>(); List<string> listGroupingMeasures = new List<string>(); List<string> listGroupingRows = new List<string>(); for (int i = 0; i < lstGroupingColumns.Items.Count; i++) { ListItem li = (ListItem)lstGroupingColumns.Items[i]; listGroupingColumns.Add(li.ValueMember.ToString()); } for (int i = 0; i < lstGroupingMeasures.Items.Count; i++) { ListItem li = (ListItem)lstGroupingMeasures.Items[i]; listGroupingMeasures.Add(li.ValueMember.ToString()); } for (int i = 0; i < treDataSource.Nodes[0].Nodes.Count; i++) listGroupingRows.Add(treDataSource.Nodes[0].Nodes[i].Tag.ToString());
DataTable dtPivot = PivotDataTable.DoReportPivot(listGroupingMeasures, listGroupingRows, listGroupingColumns, dt, false, null); ultraGrid.DataSource = dtPivot; ultraGrid.DataBind(); UltraGridBand band = ultraGrid.DisplayLayout.Bands[0]; for (int j = 0; j < dtPivot.Columns.Count; j++) { DataColumn dc = dtPivot.Columns[j]; if (!listGroupingRows.Contains(dc.Caption)) { UltraGridGroup uggParent = null; string[] strSplit = dc.Caption.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < strSplit.Length; i++) { try { UltraGridGroup uggTemp = band.Groups.Add(i.ToString() + "-" + strSplit[i], strSplit[i]); if (uggParent != null) uggTemp.RowLayoutGroupInfo.ParentGroup = uggParent; uggParent = uggTemp; } catch { uggParent = band.Groups[i.ToString() + "-" + strSplit[i]]; } if (i == strSplit.Length - 1) { band.Columns[dc.Caption].Header.Caption = strSplit[0]; band.Columns[dc.Caption].RowLayoutColumnInfo.ParentGroup = uggParent; } } } }
I'm having a hard time reading this code - it's sort've mangled and there are some peices missing.Perhaps you could copy it into NotePad and then copy and paste from there rather than copying directly from whatever application you copied from. Also, you can enclose your code in a "code" block and the forums will display it in a better way.
One thing I noticed here, though, is that you are adding groups, but you are not adding any columns to the groups.
I can't do this in the designer, it needs to be set programmatically, I upgraded to 9.1 and still can't get it working
I tried this code with no luck, no data is displayed under the groups
dt.Rows)
{
;
i=0; i<lstGroupingColumns.Items.Count;i++)
)lstGroupingColumns.Items[i];
try
+drow[li.ValueMember.ToString()].ToString(), drow[li.ValueMember.ToString()].ToString());
)
uggTemp.RowLayoutGroupInfo.ParentGroup = uggParent;
uggParent = uggTemp;
}
uggParent = band.Groups[i.ToString()+
+drow[li.ValueMember.ToString()].ToString()];
(i == lstGroupingColumns.Items.Count - 1)
j = 0; j < lstGroupingMeasures.Items.Count; j++)
)lstGroupingMeasures.Items[j];
The WinGrid does not have any functionality to automatically pivot the data. The grid displays the data from the DataSource you give it. So in order to get a view like this, you would have to bind the grid to a DataSource which has the data in the structure you want.
Regarding the groups in the grid, you can't have nested groups using v8.3 of the grid. This was not supported in that version. Nested group functionality was added to v9.1 of the WinGrid along with the Groups in RowLayouts feature. The easiest way to set that up would be to use the grid designer and select "RowLayout with Groups" from the ColumnArrangement Overview section, and then you can create groups and arrange the columns in the designer.
Image 2