【问题标题】:change the background color a selected row datagridview更改所选行datagridview的背景颜色
【发布时间】:2013-02-01 09:06:36
【问题描述】:

在我的 datagridview 中,如果我点击单元格,整行的背景选择颜色应该会改变。请指导我这样做。

【问题讨论】:

  • 你自己没有投入任何精力研究这个。

标签: c#


【解决方案1】:

使用DefaultCellStyle.SelectionBackColor 或者你可以看到NanoTaboada answer

看看MSDN

【讨论】:

    【解决方案2】:

    请尝试以下代码,我认为它可能会有所帮助:

    dgv.Rows[curRowIndex].DefaultCellStyle.SelectionBackColor = Color.Blue;
    

    【讨论】:

      【解决方案3】:

      感谢您的回复。我尝试了以下方法,它成功了。

      dgvDetails.Rows[e.RowIndex].DefaultCellStyle.SelectionBackColor = Color.Blue;
      

      【讨论】:

      • 如果其中一个答案可以帮助您获得想要的结果,我建议您“接受”该答案,以感谢您的努力。
      【解决方案4】:

      您应该处理 DataGridView 的事件 RowStateChanged 并设置 SelectionBackColor。 试试下面的代码:

       DataGVEmployee.RowStateChanged += new DataGridViewRowStateChangedEventHandler(DataGVEmployee_RowStateChanged);
      
      
      
          void DataGVEmployee_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
              {
           if (e.StateChanged == DataGridViewElementStates.Selected)
                      {
                          e.Row.DefaultCellStyle.SelectionBackColor = Color.Red;
                      }
                      else
                      {
                          e.Row.DefaultCellStyle.SelectionBackColor = Color.White;
      
                      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-11
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 2015-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多