dataGridView1 CellValueChanged事件 [英] dataGridView1 CellValueChanged event

查看:777
本文介绍了dataGridView1 CellValueChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据网格视图中找到单元格中的值时更改单元格的颜色

changing the color of the cell when it finds values in the range of hundred in datagrid view

推荐答案

为CellValueChanged事件创建一个处理程序,类似这样.

Create a handler for the CellValueChanged event, something like this.

protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
{
    base.OnCellValueChanged(e);

    // Test value of cell which just changed
    if (uint.Parse(this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) == 100)
    {
        // Cell value is now 100 - make cell background red
        this.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = System.Drawing.Color.Red;
    }
    else
    {
        // Cell value is not 100 - make background white
        this.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = System.Drawing.Color.White;
    }
}


这篇关于dataGridView1 CellValueChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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