DataColumn的datagridview的替换特定的值 [英] datacolumn datagridview replace specific value

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

问题描述

我有一个DataGridView在我的C#program.after我将其绑定到数据源,我想更换一些价值在一个特定的列自动生成的rows.for比如我有具有0或1的值列,我要替换真或假。我应该怎么办?

i have a datagridview in my C# program.after i bind it to a datasource , i want to replace some value in a specific column in automatically generated rows.for example i have columns in which have 0 or 1 values , and i want to replace true or false . what should i do ?

推荐答案

见的 DataGridView.CellFormatting 事件。

此事件被称为时,它的时间格式的单元格。一个比较有用的东西,你可以在这个活动做的是改变基于单元格的值的单元格的内容和外观。

This event is called when it's time to format a cell. One of the more useful things you can do in this event is change the content and appearance of a cell based on the cell's value.

您将要学习code中的文档中,但我下面的一个片断显示了一点点,你可以做。所述CellFormatting事件下列检查,如果它的格式化在一个叫做Column3列中的单元格,如果它是与该单元格的值是0(字符串),它改变了细胞的值设定为假,细胞的背景色为红色。

You'll want to study the code in the documentation but I have a snippet below that shows a little you can do. The CellFormatting event below checks if it's formatting a cell in a column called "Column3" and if it is and the cell's value is 0 (as a string) ,it changes the cell's value to "False" and the cell's BackColor to red.

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
    if (dataGridView1.Columns[e.ColumnIndex].Name == "Column3") {
        if (e.Value.ToString() == "0") {
            e.CellStyle.BackColor = Color.Red;
            e.Value = "False";
        }
    }
}

这篇关于DataColumn的datagridview的替换特定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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