Important note.
Starting with version 13.2, GridView provides a built-in checkbox column for multiple row selection. So, to enable this type of multiple row selection in newer versions, it is sufficient to enable the GridViewOptionsSelection.MultiSelect option and then set the GridView.OptionsSelection.MultiSelectMode property to the GridMultiSelectMode.CheckBoxRowSelect value. Take a look at the How to use an unbound check box column to select grid rows example for sample code.
This example demonstrates how to add a check column to allow web-style multiple row selection. End-users can select/deselect rows, group rows or select/deselect all rows by clicking the column header. Changing a check box value does not initiate row editing.
All code related to selection resides in the GridCheckMarksSelection helper class. So, to implement this functionality in your application, you can simply add this class to your project and then create a new GridCheckMarksSelection instance.
Please note if you use the AppearanceEvenRow and AppearanceOddRow styles, by default they have a higher priority than the RowStyle event used for the selection in this example. To avoid drawing incorrect selected rows, enable the e.HighPriority option.
The GridCheckMarksSelection class also provides different ~Select methods which allow selecting data and group rows in code. To obtain selected rows, you can use the SelectedCount property and GetSelectedRow method.
Question Comments
Added By: Marc Roussel at: 10/11/2012 5:59:00 AM
Hmmm how do I use this class ?
Added By: You Logic at: 10/16/2012 4:16:54 AMWhen I select a row via code, the check box is not checked. How can I do this!?
Added By: Piotr Christ at: 2/8/2013 4:13:11 AMI had the same problem as You Logic ! How select row (with checkbox) from code ?
Added By: (no info) at: 11/25/2013 2:23:24 PMWhile this is a very nice implementation there is a problem with the code. Because you have defined selection *in the CheckMarkSelection.cs" as an ArrayList it is next to impossible to get at any values contained within each of the actual selected rows from the grid. Let's say one needs to obtain two of the values within the row...one is a string and one is an integer...how do you get the values out? There are no extension methods associated with "selection" that would allow you to enumerate the data lets say using linq or even simply doing somethin like: DataRowView theRow = (DataRowView)this.selection.GetSelectedRow(i); What happens is there is a cast error that occurs due to the generic types within the ArrayList. Granted this is necessary as we have an unknown group of column objects and values. There needs to be a built in method to access the individual values in the selected rows from "selection". I have tried 12 different methods to extract them and still a Cast error occurs.
Added By: Dave Smith 6 at: 3/4/2016 2:15:24 AM After implementing this class the column does not show, not sure what I'm doing wrong.In the constructor of my form I call new GridCheckMarksSelection(gridViewSearchInventory);
and then in the form load i bind to my grid Added By: Sasha (DevExpress Support) at: 3/4/2016 6:20:43 AM
Hello Dave,
I've created a separate ticket on your behalf: GridControl - The check box column is not shown when using a class from the E1271: Multiple selection using checkbox (web style) example .
We will update it shortly.
How can I modify View_Click() to invert group row selection when clicking the group checkbox ONLY?
Current implementation inverts selection when clicking anywhere in the group row.
Thank you Added By: Alisher (DevExpress Support) at: 4/14/2016 5:05:29 AM
Hello,
I've created a separate ticket on your behalf (T367815: How to invert group row selection when clicking the group checkbox only?). It has been placed in our processing queue and will be answered shortly.
How could I modify this sample so the check column is the very first column when AlignGroup SummaryInGroupRow = True?
I think this is related, but it's still confusing for me: https://www.devexpress.com/support/center/Question/Details/T365937#comment-e1c23ee5-92fd-4fd3-a2e3-b487a566d095
Thank you Added By: Alisher (DevExpress Support) at: 4/25/2016 5:18:54 AM
Hi Jacobo,
The AlignGroupSummaryInGroupRow option is available starting with version 15.2 of our components. Therefore I think that you are using the latest version of our products in your project. However, the functionality implemented in this example can be used out of the box in the mentioned version. Set the GridView's OptionsSelection.MultiSelect property to True and the OptionsSelection.MultiSelectMode property to CheckBoxRowSelect to enable it.
Would you please clarify why you are still using this example to achieve this functionality?
As for the issue with incorrect painting of column headers, we are aware of it and have already fixed it. Please take a look at the The Grid doesn't paint correctly either the column header or the cell value if AlignGroupSummaryInGroupRow is set ticket for more information.
Yes I'm in the latest version of your components, and I'm aware of the CheckboxRowSelect option.
However my original issue is the one described in : https://www.devexpress.com/Support/Center/Question/Details/T294110
(selection checkboxes are cleared when the grid is filtered). The solution to that issue sug gests to use the sample shown in this page to achieve checkbox column+filtering persistence so here I am.
My issue now is that when enabling AlignGroupSummaryInGroupRow the checkbox is shown after the grouped columns and I'd like to show it before. I did read the issue: https://www.devexpress.com/support/center/Question/Details/T365937
but it still unclear to me how can I proceed. Can you give some guidance?
thank you
Added By: Alisher (DevExpress Support) at: 4/26/2016 5:40:29 AM
Hi Jacobo,
Thank you for the clarification.
At present setting the AlignGroupSummaryInGroupRow property forces the Grid to display fixed columns after grouped columns. I don't see an easy way to overcome this behavior. I have created a separate ticket (GridControl - Setting the AlignGroupSummaryInGroupRow forces the Grid to display fixed columns after grouped columns) and passed it to our developers. We will examine the possibility of placing fixed columns before grouped columns. Please add that ticket to your Favorites to be notified of our progress.
when the form set on right to left , the checkbox not appears on group row