欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF DataGrid选中改变时,还原选中行

程序员文章站 2022-03-07 17:06:12
...
if (index != dataGrid1.SelectedIndex && System.Windows.Forms.MessageBox.Show("1", "", System.Windows.Forms.MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
{
    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Loaded, new Action(() =>
    {
    	dataGrid1.SelectionChanged -= dataGrid1_SelectionChanged;
        dataGrid1.SelectedIndex = index;
        dataGrid1.SelectedItem = dataGrid1.Items[index];
        dataGrid1.CurrentItem = dataGrid1.Items[index];
    	dataGrid1.SelectionChanged += dataGrid1_SelectionChanged;
    }));

    return;
}

index = dataGrid1.SelectedIndex;
相关标签: C# WPF c#