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?


3 Replies 1 reply marked as answer

AP Abinesh Palanisamy Syncfusion Team September 23, 2024 09:53 AM UTC

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

Marked as answer

?? ???? ???????? April 17, 2026 07:33 PM UTC

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.



GR Gowtham Ravi Syncfusion Team April 20, 2026 05:45 AM UTC

Hi,
In SfDataGrid, row or cell selection is performed by default using the left mouse button. In a previous query, the customer requested the ability to perform row selection using the right mouse button. Currently, there is no built‑in support for selection via right‑click.
As a workaround, we provided a solution using the onCellSecondaryTap event to meet the customer’s requirement. It is important to note that right‑click interactions typically serve one of two purposes:
  • Performing selection, or
  • Displaying a context menu
Both actions cannot be executed simultaneously on a right‑click. However, the secondary tap event can be customized based on the customer’s specific needs—either to display a context menu or to enable row selection using the right mouse button.
We hope the above explanation addresses your query clearly.
Please feel free to contact us if you have any further questions. We are happy to assist you.
Regards,
Gowtham R

Loader.
Up arrow icon