2

How to select cell in RadGridView by right mouse click?

The following code doesn't work:

private void RadGridView_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
    // ... getting grid and cell
    if (e.RightButton == MouseButtonState.Pressed)
    {
        grid.UnselectAll();
        grid.CurrentCellInfo = new GridViewCellInfo(cell);
        cell.IsCurrent = true;
        cell.IsSelected = true;
    }
}

It's strange, but selecting row works fine:

if (e.RightButton == MouseButtonState.Pressed)
{
    grid.UnselectAll();
    row.IsSelected = true;
    row.IsCurrent = true;
}
Rover
  • 2,203
  • 3
  • 24
  • 44

3 Answers3

1
if (e.RightButton == MouseButtonState.Pressed)
{
    grid.Focus();
    grid.UnselectAll();
    grid.CurrentCellInfo = new GridViewCellInfo(cell);
    grid.SelectedCells.Add(grid.CurrentCellInfo);
}
Rover
  • 2,203
  • 3
  • 24
  • 44
0

Did you try grid.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect ?

franssu
  • 2,422
  • 1
  • 20
  • 29
0

Use the OriginalSource the get the Cell that was clicked (remember that can also be null) and set the IsSelected value.

Florian
  • 5,918
  • 3
  • 47
  • 86