C# 隐藏DataGridView默认行选择
在这里,我使用一些颜色代码通过刷新按钮高亮显示行,但每次刷新后DataGridView选择始终设置为第一行,默认选定的colorBlue将始终覆盖我的第一行颜色 我需要在刷新后隐藏第1行中的默认颜色,然后用户选择网格视图 选择一行,所以此时行选择对我来说并不重要 这是我的代码…我希望这能解释我的问题C# 隐藏DataGridView默认行选择,c#,datagridview,colors,C#,Datagridview,Colors,在这里,我使用一些颜色代码通过刷新按钮高亮显示行,但每次刷新后DataGridView选择始终设置为第一行,默认选定的colorBlue将始终覆盖我的第一行颜色 我需要在刷新后隐藏第1行中的默认颜色,然后用户选择网格视图 选择一行,所以此时行选择对我来说并不重要 这是我的代码…我希望这能解释我的问题 private void btnRefreshCutDGV_Click(object sender, EventArgs e) { tablePlanMainBL.ColorMainGrid
private void btnRefreshCutDGV_Click(object sender, EventArgs e)
{
tablePlanMainBL.ColorMainGrid(dgvMainCut);
}
public void ColorMainGrid(DataGridView dgvCol)
{
dgvCol.Refresh();
foreach (DataGridViewRow row in dgvCol.Rows)
{
if (int.Parse(row.Cells[7].Value.ToString()) == 2)
{
row.DefaultCellStyle.BackColor = Color.OrangeRed;
}
else if (int.Parse(row.Cells[7].Value.ToString()) == 3)
{
row.DefaultCellStyle.BackColor = Color.SpringGreen;
}
}
}
刷新后设置
dgvCol.CurrentCell = null;