Prevent select rows by condition in SfDataGrid

Hello,

I have a grid with custom GridCheckBoxSelectorCellRenderer, that shows the checkbox when the datasource Nyomtatva value is true (cannot see in the images). The requirement is selecting multiple rows with GridSelectionMode.Extended

This works fine:

Next step I should prevent any selection (cell, row) in all rows wo the checkbox is not showing.

Currently I can select these rows too:



I try prevent selection with this code but this is not working fine:


        private void PrimaryGrid_SelectionChanging(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangingEventArgs e)
        {
            var z = e.AddedItems.Where(w => ((RaktariAnyagKivetListItemDto)w).Nyomtatva == false).FirstOrDefault();

            if (z != null)
            {
                e.Cancel = true;
            }
        }

So summary my question is: how can I prevent any selection in rows wo the checkbox is not showing?



Thank you for help!

Best Regards,

László


14 Replies 1 reply marked as answer

SD Swathi Dhatchanamoorthi Syncfusion Team May 22, 2023 03:52 PM UTC

Hello László,

We are currently checking your reported problem with provided information and we need a time to validate this. We will update you with further details on May 24, 2023.



SZ SZL replied to Swathi Dhatchanamoorthi May 22, 2023 04:54 PM UTC

Hello, ok, thank you very much!



SB Sweatha Bharathi Syncfusion Team May 24, 2023 01:36 PM UTC

Hello László,


We are still checking your reported problem with provided information and we need a time to validate this. We will update you with further details on May 26, 2023.



SB Sweatha Bharathi Syncfusion Team May 26, 2023 01:53 PM UTC

Hello László,


Based on the provided information, your requirement to prevent the selection of certain rows in SfDataGrid can be achieved by customizing the RowSelectionController to handle key and pointer operations. We have prepared a sample based on your requirements. Please review the sample and let us know if you need any further assistance.


Attachment: Sample_11a65d42.zip


SZ SZL May 28, 2023 11:45 AM UTC

Hello Sweatha,

Thank you very much, its almost perfect. Only problem that with SHIFT key, I can select the denied rows:





SB Sweatha Bharathi Syncfusion Team May 29, 2023 01:58 PM UTC

Hello László,


We have prepared the sample and addressed your requested concerns. Please review the sample and let us know if you have any further concerns.


Attachment: Sample_1f0d2577.zip


SZ SZL replied to Sweatha Bharathi June 1, 2023 09:09 PM UTC

Thank you very much, its works fine!



SB Sweatha Bharathi Syncfusion Team June 2, 2023 12:22 PM UTC


László,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you
😊.



SZ SZL replied to Sweatha Bharathi June 22, 2023 01:48 PM UTC

Hello,


I still have a problem with this, that I just noticed.


I use this event for the SfDataGrid:

   PrimaryGrid.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;


But when I setup the above selection method, the event is not firing anymore.

Can you help me please why this happen?


Thank you!


BR, László



SB Sweatha Bharathi Syncfusion Team June 23, 2023 12:04 PM UTC

László,

Based on the information provided, we have checked the reported issue of "PrimaryGrid.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged; the event is not firing anymore."  We were unable to replicate the issue from our end, as it is working fine as expected. We have prepared a sample for the same, Please review the sample and let us know if you are still experiencing the same issue. please modify the sample based on your scenario and provide us with the following details:

  • Dis you using more than one DataGrid or DetailsViewDataGrid?
  • Modified sample with issue reproducing customization
  • Video demonstrating the issue

This will be helpful for us to investigate further and provide you with a solution at the earliest.



Attachment: Sample_6f299aa9.zip


SZ SZL replied to Sweatha Bharathi June 23, 2023 07:08 PM UTC

Thank you! I not clearly understand what happened in my side, but I move the event subscription under all other grid settings and works fine. :)


When I move this line in your example:

sfDataGrid.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;

to line 37.

it will not work in your exampe,

when I move back it will work. :)


I dont know the reason but works now. Thank you!



SP Sreemon Premkumar Muthukrishnan Syncfusion Team June 26, 2023 02:57 PM UTC

László,

We are glad to hear that. When using the custom selection controller, you need to hook the CollectionChanged event after initializing the custom Selection controller.

Regards,

Sreemon Premkumar M.



Marked as answer

SZ SZL June 26, 2023 07:59 PM UTC

Yes, thank you!



SB Sweatha Bharathi Syncfusion Team June 27, 2023 09:40 AM UTC

László,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you
😊.


Loader.
Up arrow icon