question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option to configure DataGrid Right Click Row Selection Behavior

See original GitHub issue

Is your feature request related to a problem? Please describe.

A recent PR caused a regression in behavior for the DataGrid Right Click Context Menu:

https://github.com/AvaloniaUI/Avalonia/pull/6394

This PR changed the DataGrid Right click behavior to select the item beneath the mouse, instead of retaining the existing DataGrid selections.

At least for my framework and app that uses it, this fix isn’t a desirable behavior and caused a regression. Although I can see why it might be desirable for many apps.

For my app the DataGrid ContextMenu has the following options:

Copy - Cell Contents Copy - Column Copy - Row Copy - Selected Copy - DataGrid

Users will frequently right click on an unselected cell to copy it’s contents. These cells aren’t always selected since users might want to copy a description value in something like a property inspector.

Additionally, in my app the DataGrid selections create controls based on the selections, which can in turn create their own controls. So retaining the existing selections is really important. Otherwise a lot of extra sub-controls get updated which is distracting, takes extra loading time, and users then often have to reselect their previous selections. And multi-selecting makes this problem even worse, since it also reselects a single row if the target is different from one of the currently selected rows.

Describe the solution you’d like A clear and concise description of what you want to happen.

Can you add an option for controlling the DataGrid right click selection behavior so both options are possible? Specifically, there should be the following options for the DataGrid

  • Right Clicking updates selection to target (new behavior with that fix)
  • Right Clicking doesn’t update the selection to the target (previous behavior before the fix)

Specifically for the DataGridCell.DataGridCell_PointerPressed()

Describe alternatives you’ve considered A clear and concise description of any alternative solutions or features you’ve considered.

The PR that added the fix modified the DataGridCell_PointerPressed() to update the selection when right clicking. I could try overriding that event handler, but that function still needs to be called to get the Column from the DataGridCellPointerPressedEventArgs it generates. And the Column is needed for the Copy - Column shortcut in the Content Menu. I’m unaware of any other way to get the column, since the DataGridCell.OwningColumn is internal.

It would be really helpful if the following were public too:

DataGridCell.OwningColumn DataGridCell.OwningGrid DataGridRow.OwningGrid

(The OwningGrid currently requires searching up the Parent controls tree to determine the DataGrid)

Additional context Add any other context or screenshots about the feature request here.

Here’s a screenshot of the test app (the primary app is internal), but I’m hoping to get the framework out soon:

image

https://github.com/garyhertel/Atlas

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
timuniecommented, Aug 13, 2022

@sergevm you can try tunneling the event like explained here https://docs.avaloniaui.net/misc/wpf/tunnelling-events

0reactions
sergevmcommented, Aug 13, 2022

Interesting … if there is an expensive action behind row selection, it would be nice if you could indeed prevent the row selection from happening on right click. Running into the performance impact myself actually, and in my context, still had some code that listens on pointer pressed, to select the row from code (the code was written before the aforementioned PR). Is there an alternative in the mean time, similar to Preview[EVENT] etc?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Right-click to select DataGrid Row not working
I've read a few questions asking how to achieve DataGridRow selection when there's a right-click on the grid. The answers show a few...
Read more >
Change row selection on right-click in UI for WPF
I am using a context menu that gets loaded in the "CellLoaded" ... When the user right-clicks the cell, the row selection doesn't...
Read more >
Keyboard and Mouse Behavior in the DataGrid Control ...
Default Mouse Behavior ; CTRL+click a row, If SelectionMode is set to Extended, modifies a non-contiguous multi-row selection. If the row is ...
Read more >
JavaScript Data Grid: Row Selection
Selecting a row and holding down Shift while clicking a second row will select the range. Configure row selection with the following properties:....
Read more >
Selection in Blazor DataGrid Component
Selection provides an option to highlight a row or a cell. It can be done through simple mouse down or arrow keys. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found