DataGridView在判定datatable后,如何根据datatable不同的行状态,显示不同的背景色
解决方案 »
- 在C++中调用C#编写的DLL,函数返回值为string,在C++中用CString去接收怎么是乱码?
- WCF,“反序列化”出错
- 请教:如链接所示的这种属性页有什么简单实现的实现方式?
- 如何用应用程序自动登陆系统
- 救助:关于datagrid1嵌套datagrid2,如何调用datagrid2编辑、修改、删除事件?急急。。。。。。。。。
- 我想从一个文件夹 把.wmv的文件的1/2 COPY到别的文件夹中.(这1/2也能看),怎么实现呀?
- 如何能够连接到处于内网的数据库服务器
- 如何用c# 获取关闭浏览器上的关闭按扭事件啊
- 求一个自定义webcontrol的例子
- 几天没上了,论坛换了个QQ装。今天我登录的校验码是:88888
- 在状态栏中 ,下图该部分怎么做?
- winform 实现图片批量上传
for()
{
switch()
{
g.drawline();
}
}这样结构的东西
如何设置选中行的背景颜色和字体颜色?
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Transparent;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Red;
dataGridView1[0, 1].Style.ForeColor = Color.Red; //颜色
上面的方法都不行。
RowDataBound()我怎么找不到这个事件
{
if(e.RowIndex != -1 && e.ColumnIndex == 1 && e.Value != null && e.Value.ToString() == "")
{
e.CellStyle.BackColor = Color.Red;
e.CellStyle.ForeColor = Color.Blue;
e.CellStyle.SelectionBackColor = Color.BlueViolet;
}
}
或
DataGridViewCellStyle style = new DataGridViewCellStyle();
foreach(DataGridViewRow aRow in dataGridView1.Rows)
{
if(aRow.Cells[0].Value.ToString().Equals(""))
{
style.BackColor=Color.Blue;
aRow.DefaultCellStyle=style;
}
}
这个不是属性或事件,请先用别人能听懂的方法解释你的需求
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataTable dt = (DataTable)dataGridView1.DataSource;
if (e.RowIndex >= dt.Rows.Count || e.RowIndex < 0)
{
return;
}
DataRowState state = dt.DefaultView[e.RowIndex].Row.RowState;
switch (state)
{
case DataRowState.Added: e.CellStyle.BackColor = Color.Red; break;
case DataRowState.Modified: e.CellStyle.BackColor = Color.Yellow; break;
case DataRowState.Unchanged: break;
}
}