如何根据条件更改数据网格视图中的文本前颜色 [英] how to change the text fore color in datagrid view based on condition
问题描述
public void view_load_tenthclass_marks()
{
//自动调整列大小的代码
dataGridView3.AutoResizeColumns();
dataGridView3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
ConnectionStringSettings consettings = ConfigurationManager.ConnectionStrings [smssms];
string connectionString = consettings.ConnectionString;
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataTable dt = new DataTable();
cn.Open();
//传递查询
sqlcmd =新的SqlCommand(@select * from tenthclass_marks ,cn);
sda = new SqlDataAda pter(sqlcmd);
//在SQL数据适配器中填充数据
sda.Fill(dt);
//绑定它在DataGrid视图中
dataGridView3.DataSource = dt;
cn.Close();
}
this是我的代码,用于检索所有学生的标记。如果学生得到< 35然后该行颜色应该更改为另一种颜色。如何写????
public void view_load_tenthclass_marks()
{
//this code for auto resize of columns
dataGridView3.AutoResizeColumns();
dataGridView3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
ConnectionStringSettings consettings = ConfigurationManager.ConnectionStrings["smssms"];
string connectionString = consettings.ConnectionString;
SqlConnection cn = new SqlConnection(connectionString);
SqlCommand sqlcmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataTable dt = new DataTable();
cn.Open();
//pass query
sqlcmd = new SqlCommand(@"select * from tenthclass_marks ", cn);
sda = new SqlDataAdapter(sqlcmd);
//Fill the data in the SQL Data Adapter
sda.Fill(dt);
//Bind it in the DataGrid View
dataGridView3.DataSource = dt;
cn.Close();
}
this is my code for retrieving marks of all students.if student get <35 then that row colour should be change to another color .how to write ????
推荐答案
您好,
请参考以下链接。
更改个人DataGridView基于列值的行颜色 [ ^ ]
http://stackoverflow.com/questions/2189376/c-sharp-how-to-change-row-color-in-datagridview [ ^ ]
谢谢
Hello,
Please refer the below links.
Change individual DataGridView row colors based on column value[^]
http://stackoverflow.com/questions/2189376/c-sharp-how-to-change-row-color-in-datagridview[^]
Thanks
这篇关于如何根据条件更改数据网格视图中的文本前颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!