Ticket Q570580
Visible to All Users

CheckBoxRowSelect - Selection is cleared when you click outside of a check box column

created 11 years ago

Hi,

I'm using CheckBoxRowSelect to select some rows on the xtragrid.
The option selection is set that way :

C#
this.gridViewAdresses.OptionsSelection.CheckBoxSelectorColumnWidth = 30; this.gridViewAdresses.OptionsSelection.EnableAppearanceFocusedCell = false; this.gridViewAdresses.OptionsSelection.EnableAppearanceFocusedRow = false; this.gridViewAdresses.OptionsSelection.EnableAppearanceHideSelection = false; this.gridViewAdresses.OptionsSelection.MultiSelect = true; this.gridViewAdresses.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; this.gridViewAdresses.OptionsSelection.ShowCheckBoxSelectorInColumnHeader = DevExpress.Utils.DefaultBoolean.True;

My problem is that if I click on another cell, it deselect all previous checked rows and select the row I just click on.
I want to keep the rows I checked previously, and only select a new one when the checkbox is clicked, and only on that cell, not when I click on another one.

What am I doing wrong ?

regards

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
Now it works as expected. We may reconsider this behavior and change it (or add an option for it) in the future. When it happens, we will inform you about it in the Provide a capability to keep selection when clicking outside the Check column thread. Please add it to your favorites.
As a workaround, handle the GridView.MouseDown and MouseUp events, and store selected row handles. After a mouse click is processed, restore the selection:

C#
private void KeepSelection(MouseEventArgs e, GridView view) { DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = view.CalcHitInfo(e.Location); if (hi.InRow) { if (hi.Column.FieldName != "DX$CheckboxSelectorColumn") { int[] selectedRows = view.GetSelectedRows(); bool isSelected = view.IsRowSelected(hi.RowHandle); BeginInvoke(new Action(() => { for (int i = 0; i < selectedRows.Length; i++) view.SelectRow(selectedRows[i]); if (!isSelected) view.UnselectRow(hi.RowHandle); })); } } }

I have attached a project illustrating this approach. Please test it and let us know your result.

    Show previous comments (17)
    DevExpress Support Team 9 years ago

      Hi Sandeep,

      I noticed that this ticket was created by another person, so I want to clarify some details to avoid any misunderstanding. Is the issue you are talking about related to the code above, or do you not use this approach in your application? Can you show us the code used to setup this column and describe how it is bound to the datasource?

      SR SR
      Sandeep Reddy 6 9 years ago

        My Issue is not related to code mentioned above. I am trying to bind simple datatable with two data columns. Once the datasource is set and binded to grid. I am trying to set below two properties
        gridViewAdresses.OptionsSelection.MultiSelect = true;
        this.gridViewAdresses.OptionsSelection.MultiSelectMode =DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
        Here I am able to see the checkbox as first column along with other two datacolumns of  datasource. But my concern at any point of time  I am able to check only one datarow checkbox. By selecting the  control I can can select multi rows checkboxes. But I do not want to have that way. I should be able to persist the previous checked checkbox state when I select other row checkbox.

        Nadezhda (DevExpress Support) 9 years ago

          Hello,

          To process your recent post more efficiently, I created a separate ticket on your behalf: How to prevent multi row selection when the CheckBoxRowSelect option is used. This ticket is currently in our processing queue. Our team will inform you as soon as we have any updates.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.