How can I select a row on right click?
How can I select a row on right click? I just saw this thread where this behavior was marked as a bug and fixed: https://www.syncfusion.com/forums/189498/how-to-disable-selection-when-mouse-right-click.
However, I want to highlight the row when I do a right click, how can I replicate this behavior on newer versions of the library?
Hi Pablo,
In SfDataGrid, direct support for right-click selection is not available. However, there is a workaround to achieve this behavior using the onCellSecondaryTap event. This event is triggered when a cell is tapped with a secondary button (right-click). We can implement the selection logic by using SfDataGrid.controller along with the rowIndex and columnIndex details from the onCellSecondaryTap event. A sample and code snippet has been provided for your reference. Please review it for further details.
Code snippet :
|
onCellSecondaryTap: (details) { int rowIndex = details.rowColumnIndex.rowIndex - 1; int colIndex = details.rowColumnIndex.columnIndex; if (rowIndex >= 0 && colIndex >= 0) { // Check if the right-clicked row is already selected, Remove selection. if (_dataGridController.selectedRows .contains(employeeDataSource._employeeData[rowIndex])) { selectedRows.remove(employeeDataSource._employeeData[rowIndex]); _dataGridController.selectedRows = List.from(selectedRows); // Moves the current cell to the tapped cell when the navigation mode is set to 'cell'. _dataGridController .moveCurrentCellTo(RowColumnIndex(rowIndex, colIndex)); } else { // If not selected, select the row. _dataGridController.selectedRows = []; selectedRows.add(employeeDataSource._employeeData[rowIndex]); _dataGridController.selectedRows = List.from(selectedRows); // Moves the current cell to the tapped cell when the navigation mode is set to 'cell'. _dataGridController .moveCurrentCellTo(RowColumnIndex(rowIndex, colIndex)); } } }, |
Regards,
Abinesh P
Attachment: SfDataGrid_f2493787.zip
Interesting discussion — it highlights how context menu behavior in grid components can sometimes affect row selection and user experience, especially when working with multi-row selection and right-click actions. Ensuring consistent selection behavior is important for maintaining predictable UI interactions in enterprise applications.
That’s where a code review company becomes valuable — it helps identify UI/UX logic issues, improve code consistency, and ensure that components like grids and context menus behave correctly across different scenarios.
- Performing selection, or
- Displaying a context menu
- 3 Replies
- 4 Participants
- Marked answer
-
PP Pablo Padilla
- Sep 22, 2024 07:36 PM UTC
- Apr 20, 2026 05:45 AM UTC