Hello,
I'd like to mark the non-grouped rows in a selected group in order to copy those selected rows.
Unfortunately, selecting with "GetAllNonGroupByRows" in "this.ultraGrid1.Selected.Rows.AddRange( this.ultraGrid1.Rows.GetAllNonGroupByRows() );"gets me all non-grouped rows, whereas I only like to select the non-grouped rows of a previously selected, certain group.
Looping through like in the following lines is pretty copious, is there a better way than that?
UltraGridRow[ allRowsNotGrouped = gridReport.Rows.GetAllNonGroupByRows(); //all non-grouped rowsList<UltraGridRow> allRowsNotGroupedInSelectedGroup = new List<UltraGridRow>();foreach (UltraGridRow row in allRowsNotGrouped){ if (row.ParentRow.Selected == true) // select rows only from the selected group { allRowsNotGroupedInSelectedGroup.Add(row); }}UltraGridRow[ allRowsNotGroupedInSelectedGroup2 = (UltraGridRow[)allRowsNotGroupedInSelectedGroup.ToArray(); // gridReport.Selected.Rows.AddRange((UltraGridRow[)allRowsNotGroupedInSelectedGroup2);
Moreover, the last line throws an exception ("Object reference not set to an instance of an object."), although the array "allRowsNotGroupedInSelectedGroup2" is filled with rows.
Hi,
GetAllNonGroupByRows is a method on a rows collection. You don't have to call it on the root level collection - what you want is to call it on the child rows collection under the selected GroupByRow.
Something like this:
// Get the selected row and cast it to a GroupByRow, if possible. UltraGridGroupByRow groupByRow = this.ultraGrid1.Selected.Rows[0] as UltraGridGroupByRow; // Make sure that it really was a GroupByRow. if (groupByRow != null) { // Get all of the selected GroupByRow's child rows that are not GroupByRows. UltraGridRow[ childRows = groupByRow.Rows.GetAllNonGroupByRows(); // Clear any existing selection. this.ultraGrid1.Selected.Rows.Clear(); // Select all the child rows. if (childRows != null && childRows.Length > 0) this.ultraGrid1.Selected.Rows.AddRange(childRows); }