【问题标题】:Hide DataGridView default Row Selection隐藏 DataGridView 默认行选择
【发布时间】:2014-02-08 13:54:59
【问题描述】:

在这里,我使用一些颜色代码通过刷新按钮突出显示行,但 DataGridView 选择总是在每次刷新后设置为第一行,默认选择的颜色(蓝色)将始终覆盖我的第一行颜色。

刷新后我需要在第 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;
        }            
    }
}

【问题讨论】:

    标签: c# datagridview colors


    【解决方案1】:

    刷新后设置

    dgvCol.CurrentCell = null;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 2015-01-09
      • 2014-12-04
      相关资源
      最近更新 更多