单击鼠标右键选择单元格

时间:2012-08-23 12:52:32

标签: c# .net wpf telerik radgridview

如何通过鼠标右键单击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;
}

3 个答案:

答案 0 :(得分:1)

if (e.RightButton == MouseButtonState.Pressed)
{
    grid.Focus();
    grid.UnselectAll();
    grid.CurrentCellInfo = new GridViewCellInfo(cell);
    grid.SelectedCells.Add(grid.CurrentCellInfo);
}

答案 1 :(得分:0)

您是否尝试过grid.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect?

答案 2 :(得分:0)

使用OriginalSource获取单击的Cell(记住也可以为null)并设置IsSelected值。