2

如何通过鼠标右键单击 RadGridView 中的单元格?

以下代码不起作用:

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;
    }
}

这很奇怪,但选择行工作正常:

if (e.RightButton == MouseButtonState.Pressed)
{
    grid.UnselectAll();
    row.IsSelected = true;
    row.IsCurrent = true;
}
4

3 回答 3

1
if (e.RightButton == MouseButtonState.Pressed)
{
    grid.Focus();
    grid.UnselectAll();
    grid.CurrentCellInfo = new GridViewCellInfo(cell);
    grid.SelectedCells.Add(grid.CurrentCellInfo);
}
于 2012-08-23T14:30:52.490 回答
0

你试过 grid.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect 吗?

于 2012-08-23T13:03:57.127 回答
0

使用 OriginalSource 获取被点击的单元格(记住它也可以为空)并设置 IsSelected 值。

于 2012-08-23T13:07:46.133 回答