始终有一个选定的DataGrid行

时间:2012-07-26 12:25:48

标签: wpf wpfdatagrid

我现在正在使用WPF dataGrid并面临一个问题。我需要dataGrid始终有一个选定的行。永远只有一个。

有可能吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

<DataGrid SelectionMode="Single" SelectionUnit="FullRow" PreviewMouseDown="PreviewMouseDown"/>

编辑:

    private void PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            e.Handled = true;
    }