Search code examples
c#winformsinfragisticsultrawingrid

Select multiple Rows with UltraGrid


I am new to Infragistics using UltraGrid.

I am trying to select multiple rows using checkbox column (or if there is another idea)

I have a code for DataGridView to select multiple rows and insert it to list, than try to delete or to do code with selected items.

//get the selected item
        List<DataGridViewRow> selectedRows = (from row in Detail_shanuDGV.Rows.Cast<DataGridViewRow>()
                                              where Convert.ToBoolean(row.Cells["checkBoxColumn1"].Value) == true
                                              select row).ToList();

But when I try to use this code with UltraGrid like this

List<UltraGrid> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGrid>()
                                        where Convert.ToBoolean(row.Cells["caption"].Value) == true
                                        select row).ToList();

It gives me this error

'UltraGrid' does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'UltraGrid' could be found So if theres another idea or how to find solution to solve this error. By the way I am using hierarchical UltraGrid with checkbox column, in my UltraGrid I have Master/Details data


Solution

  • You should cast to UltraGridRow not to UltraGrid

    List<UltraGridRow> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGridRow>
                                    where Convert.ToBoolean(row.Cells["caption"].Value) == true
                                    select row).ToList();
    

    Also, probably you need another level of filtering on those rows. For example, it is not clear if the checkbox for the column Caption is on the master or in the details pane of the grid. Also if you have a GroupBy display option then you need to add also another condition to filter only the required rows

    For example, suppose that you want to apply this logic but only the rows that are in the details pane. In Infragistcs terms this second pane is called Band and every row has a property for the Band to which it belongs. And the Band has a property Index, so you get

    List<UltraGridRow> selectedRows = (from row in ultraGrid1.Rows.Cast<UltraGridRow>
                         where row.Band.Index == 1 && 
                         Convert.ToBoolean(row.Cells["caption"].Value) == true
                         select row).ToList();
    

    Notice that you first check for the Band index and only if this row is on second band you check for the cell value (Because If there is no "caption" column in the first band you get an NRE)