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ó
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.
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.
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
Hello Sweatha,
Thank you very much, its almost perfect. Only problem that with SHIFT key, I can select the denied rows:
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
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😊.
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ó
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
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!
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.
Yes, thank you!
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😊.