1
A
回答
2
使用cellformat事件可以帮助你和这个例子应该让你在路上:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace CSCellFormat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
String strConn = "Server = .;Database = AdventureWorks; Integrated Security = SSPI;";
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter da = new SqlDataAdapter("Select * from HumanResources.Employee", conn);
da.Fill(dt);
dataGridView1.DataSource = dt;
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataRowView drv;
if (e.RowIndex >= 0)
{
drv = dt.DefaultView[e.RowIndex];
Color c;
if (drv["Gender"].ToString() == "M")
{
c = Color.LightBlue;
}
else
{
c = Color.Pink;
}
e.CellStyle.BackColor = c;
}
}
}
}
相关问题
- 1. 更改WPF Datagrid行颜色
- 2. 更改Silverlight Datagrid中的行颜色
- 3. Xceed datagrid - 基于DateTime值更改datarow颜色
- 4. 更改单个细胞的基于细胞的DataGrid中值的颜色
- 5. 基于值更改单元格颜色
- 6. 在DataGrid更改行的颜色WPF
- 7. 基于来自sercer的值更改表行的颜色
- 8. 使用materializecss更改基于mysqli值的表的行颜色
- 9. SSRS基于组更改行颜色?
- 10. 基于列值的JTable行颜色更改 - 弹出单击
- 11. 如何更改行基于单元格值的背景颜色
- 12. 如何更改基于字符串值的datagridview行颜色
- 13. 在flash中更改DataGrid的颜色cs4
- 14. Spark DataGrid备选行颜色更改
- 15. 在运行时更改Datagrid wpf中的行的背景颜色
- 16. 基于单元格值的颜色行
- 17. 如何更改基于ListBoxItem的ListBoxItem的背景颜色值
- 18. 我想改变DataGrid的颜色在C#
- 19. 更改基于价值的背景颜色
- 20. chart.js基于值的条形图颜色更改
- 21. 更改基于值的Excel单元格颜色
- 22. 基于散列值单击时更改按钮的颜色
- 23. WPF DataGrid - 基于隐藏值的不同单元格颜色
- 24. 更改精简框架DataGrid中的行颜色
- 25. 更改dojo dataGrid中的行字体颜色
- 26. 如何更改DataGrid视图中的行颜色
- 27. 更改XAML颜色相对于其他XAML颜色的值?
- 28. 基于背景颜色更改微调器文本颜色
- 29. 更改中值颜色geom_boxplot
- 30. 用于Primefaces的DataGrid,这不会更改颜色
这是Windows窗体,ASP.NET,Silverlight的,WPF,...? – 2010-06-09 18:09:16
Winforms C#Datagrid桌面。 – Ricky 2010-06-09 18:26:07