当我检查c#windows应用程序中的复选框时,如何更改datagridview行中的颜色? [英] How to change the color in datagridview row when i check the checkbox in c# windows applications?

查看:84
本文介绍了当我检查c#windows应用程序中的复选框时,如何更改datagridview行中的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变颜色的datagridview行当我检查在C#窗口应用程序的复选框?我有选择一个复选框代码是在标题列中的datagridview它检查所有复选框并改变背景颜色在一个DataGridView行,但我想检查一个复选框和相应的datagridview行会改变颜色



请帮帮我



< b>我尝试了什么:



how to change the color in datagridview row when i check the check box in C# windows applications?i have code for select one check box is in header column in datagridview it checks all check boxes and changing background color in a datagridview rows but i want when check one check box and corresponding datagridview row will change color

please help me

What I have tried:

void ckBox_CheckedChanged(object sender, EventArgs e)
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            DataGridViewCheckBoxCell check = row.Cells["Chk"] as   DataGridViewCheckBoxCell;
            if (Convert.ToBoolean(check.Value) == true)
                row.DefaultCellStyle.BackColor = Color.Wheat;
            else
                row.DefaultCellStyle.BackColor = Color.White;
        }
        this.dataGridView1.EndEdit();
    }

推荐答案

处理CellContentClick事件,检查是否单击了复选框单元格并更改DefaultRowStyle



Handle CellContentClick event, check that checkbox cell is clicked and change DefaultRowStyle

 Private void dgv_CellContentClick(object sende,DataGridViewCellEventArgs e) {
// check the field value that you need...

dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FireBrick;
dgv.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White;
}


DatagridView1 [_ColumnIndex,_RowIndex] .Style.BackColor = color.White;

这里_ColumnIndex&_rowIndex分别是列号和行号,您想要更改颜色。
DatagridView1[_ColumnIndex, _RowIndex].Style.BackColor =color.White;
Here _ColumnIndex & _rowIndex are column number& row numbers respectively, which you want to change the color.


这篇关于当我检查c#windows应用程序中的复选框时,如何更改datagridview行中的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆