DataGrid中行背景色和字体颜色的设置

DataGrid加载事件:

private void dgvNotesManage_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            try
            {
                DataRowView drv = e.Row.Item as DataRowView;
                if (drv != null)
                {
                    if (!drv["NoteCategory"].ToString().IsNullOrEmpty())
                    {
                        if (drv["NoteCategory"].ToString().Trim() == "重要")
                        {
                           
                            e.Row.Foreground = new SolidColorBrush(Colors.Red);//前景色即字体的颜色
                            e.Row.Background = new SolidColorBrush(Colors.Red);//背景色
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                  MessageBox.Show(ex.Message);

            }
        }

你可能感兴趣的:(.NET,WinForm)