C# C自定义datagridview列

C# C自定义datagridview列,c#,datagridview,C#,Datagridview,如何自定义DataGridView的列插入图像,使用不同的字体设置文本。。。基于列的当前值 例如: 如果列的值=0,我想显示“否”,如果列的值=1,我想显示“是”或放置其他图像 在JAVA中,我使用CellRenderer,如果我将列的值从0更改为1,则渲染器本身负责自动将单词从“否”更改为“是” 如何在C中执行相同的操作?您应该使用CellFormatting事件 例如: private void dataGridView1_CellFormatting(object sender, Data

如何自定义DataGridView的列插入图像,使用不同的字体设置文本。。。基于列的当前值

例如:

如果列的值=0,我想显示“否”,如果列的值=1,我想显示“是”或放置其他图像

在JAVA中,我使用CellRenderer,如果我将列的值从0更改为1,则渲染器本身负责自动将单词从“否”更改为“是”

如何在C中执行相同的操作?

您应该使用CellFormatting事件

例如:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "Value")
    {
        if (e.Value != null)
        {
            int intValue = (int)e.Value;
            e.Value = (intValue == 0) ? "NO" : "YES";
        }
    }
}

使用网格的Rowdatabound事件…更多详细信息请参考或一个好的链接,我是C新手,thnx:。@Dhaval DataGridView不等于GridView。我相信OP使用的是winforms。@SriramSakthivel thnx这正是我要寻找的:。这是正确的答案。我正在动态创建datagridview,如何将此方法与动态创建的datagridview关联?或者我应该创建一个从datagridview扩展的类?您应该将事件处理程序分配给CellFormatting事件:yourDataGridView.CellFormatting+=dataGridView1\u CellFormatting;thnx但是为什么+=而不是=?因为这是订阅事件的方式。