是否可以更改datagridview复选框列(刻度)颜色更改? [英] Is it possible to change datagridview checkbox column (tick) color changed?
本文介绍了是否可以更改datagridview复选框列(刻度)颜色更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i want to change the color to green when checkbox column cell value is checked(Selected/Ticked) and to red if its not(Selected/Ticked)
>
我该怎么做?
我尝试过:
datagridview1.Rows [e.rowindex] .Columns [e.columnindex] .Style = color.green;
how can i do this?
What I have tried:
datagridview1.Rows[e.rowindex].Columns[e.columnindex].Style=color.green;
推荐答案
这样的事情:
Something like this:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4)
{
var check = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (check == null) return;
if ((bool)check == true)
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.ForeColor = Color.Green;
}
else
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.ForeColor = Color.Red;
}
}
}
这样的事情:
Something like this:
private void myDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 4)
{
var check = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (check == null) return;
if ((bool)check == true)
{
e.CellStyle.ForeColor = Color.Green;
}
else
{
e.CellStyle.ForeColor = Color.Red;
}
}
}
这篇关于是否可以更改datagridview复选框列(刻度)颜色更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文