Per the following thread...
https://www.syncfusion.com/forums/146939/how-do-i-de-select-a-row-after-its-selected
It appears that you are considering the ability to allow deselection when selection mode is single. We are on the current version (20). Is this planning to be implemented soon?
If not, how does one implement this in an MVVM architecture?
Hi Clay Hess,
As we mentioned earlier, we will
implement this feature in any of our upcoming release based on feasibilities and
other parameters. Meanwhile, you can achieve
your requirement using behavior like below,
C#:
|
this.AssociatedObject.PreviewMouseUp +=
AssociatedObject_PreviewMouseUp; { var rowIndex = window.dataGrid.GetVisualContainer().PointToCellRowColumnIndex(e.GetPosition(window.dataGrid.GetVisualContainer())).RowIndex; var record = window.dataGrid.GetRecordAtRowIndex(rowIndex); if (window.dataGrid.SelectedItems.Contains(record)) window.dataGrid.SelectedItem = null; } |
We have created the sample based on your requirement. Please check this and
revert us if you need further assistance for this.
Regards,
Dhanasekar M.
How would I implement in a UserControl and not a Window?
Hi Clay Hess,
Currently, we are checking the feasibilities to achieve your requirement. We
will check and update you further details on April 26, 2022.
We appreciate your patience until then.
Regards,
Dhanasekar M.
Hi Clay Hess,
You can achieve your requirement by using below code snippet,
C#:
|
internal class SelectionBehavior : Behavior<SfDataGrid> { protected override void OnAttached() { this.AssociatedObject.PreviewMouseUp += AssociatedObject_PreviewMouseUp; }
private void AssociatedObject_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { var rowIndex = this.AssociatedObject.GetVisualContainer().PointToCellRowColumnIndex(e.GetPosition(this.AssociatedObject.GetVisualContainer())).RowIndex; var record = this.AssociatedObject.GetRecordAtRowIndex(rowIndex); if (this.AssociatedObject.SelectedItems.Contains(record)) this.AssociatedObject.SelectedItem = null; }
protected override void OnDetaching() { this.AssociatedObject.PreviewMouseUp -= AssociatedObject_PreviewMouseUp; }
} |
We had modified the sample based on your requirement. Please check this and revert
us if you need further assistance for this.
Regards,
Dhanasekar M.