Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 隐藏DataGridView默认行选择_C#_Datagridview_Colors - Fatal编程技术网

C# 隐藏DataGridView默认行选择

C# 隐藏DataGridView默认行选择,c#,datagridview,colors,C#,Datagridview,Colors,在这里,我使用一些颜色代码通过刷新按钮高亮显示行,但每次刷新后DataGridView选择始终设置为第一行,默认选定的colorBlue将始终覆盖我的第一行颜色 我需要在刷新后隐藏第1行中的默认颜色,然后用户选择网格视图 选择一行,所以此时行选择对我来说并不重要 这是我的代码…我希望这能解释我的问题 private void btnRefreshCutDGV_Click(object sender, EventArgs e) { tablePlanMainBL.ColorMainGrid

在这里,我使用一些颜色代码通过刷新按钮高亮显示行,但每次刷新后DataGridView选择始终设置为第一行,默认选定的colorBlue将始终覆盖我的第一行颜色

我需要在刷新后隐藏第1行中的默认颜色,然后用户选择网格视图 选择一行,所以此时行选择对我来说并不重要

这是我的代码…我希望这能解释我的问题

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;