本文介绍了对于每个课程,我想在数据网格视图中设置前颜色和背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为View的按钮。当我点击查看按钮时,所有课程明智的细节都显示在数据网格视图中。
该代码如下;
i have one button called View. when i click the view button all course wise details is shown in data grid view.
for that code as follows;
private void All_Course_Wise_Click(object sender, EventArgs e)
{
try
{
GFun.BindConn();
sql = "select * FROM Tb_SCh_TIme_Table P PIVOT (MAX(Faculty_Code) FOR Session IN ([1],[2],[3] ,[4])) AS PVT order by course";
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, GFun.con);
SqlCommandBuilder commandbuilder = new SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
DGV_All_Course_Wise_Reports.DataSource = bindingSource1;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK);
}
}
当我点击按钮输出时,在数据网格视图中显示如下;
when i click the button output shows as follows in data grid view;
Sch_id Date Session 1 2 3 4
1 2013-01-15 AFF NR
2 2013-01-16 AFF vk
3 2013-01-16 AFF CM
4 2013-01-14 ARPA vk
5 2013-01-15 ARPA CM
6 2013-01-17 ARPA VK
7 2013-01-18 ARPA CM
8 2013-01-19 ARPA CM
每个课程的上面输出
我想在数据网格视图中设置前后地面颜色。
我该怎么办。帮助我。
(AFF和ARPA在数据网格视图中设置不同的前后颜色)
from the above output for each course i want to set fore and back ground color in data grid view.
how can i do.help me.
(AFF and ARPA set different fore & Back color in data grid view)
推荐答案
private void DataGridView1_CellFormatting(System.Object sender , System.Windows.Forms.DataGridViewCellFormattingEventArgse )
{
(If e.RowIndex >= 0 And e.ColumnIndex == DataGridView1.Columns("Course").Index)
}
int value = DataGridView1.Columns("Course").Index ;
If (value == 0)
{
e.CellStyle.BackColor = Color.Red;
e.CellStyle.ForeColor = Color.White;
}
ElseIf (value == 1)
{
e.CellStyle.BackColor = Color.Yellow;
e.CellStyle.ForeColor = Color.Black;
}
elseif .....
......
}
这篇关于对于每个课程,我想在数据网格视图中设置前颜色和背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!