datagridview行背景色
❶ 设置datagridview中某个单元格背景颜色的问题
1、首先需要在窗体中拖入一个DataGridView控件。
❷ 怎么在后台设置Datagridview行的背景颜色
属性里就有设置,或者单元格重画事件 ,重新设置底色
❸ datagridview 如何根据条件设置某一行背景颜色
private void dataGridView1_RowPrePaint(object sender, e){if (e.RowIndex = dataGridView1.Rows.Count - 1)return;DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];try{//dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值 if (dgr.Cells[0].Value.ToString() == 男){//定义画专笔,使用颜色是属深灰。 using (SolidBrush brush = new SolidBrush(Color.DarkGray)){//利用画笔填充当前行 e.Graphics.FillRectangle(brush, e.RowBounds); //将值重新写回当前行。
❹ 如何设置datagridview选择行的背景色
private void dataGridView1_RowPrePaint(object sender, e){if (e.RowIndex = dataGridView1.Rows.Count - 1)return;DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];try{//dgr.Cells[0]是当前性别列来的索引值,源用以确定判断哪一列的值
if (dgr.Cells[0].Value.ToString() == 男){//定义画笔,使用颜色是深灰。
using (SolidBrush brush = new SolidBrush(Color.DarkGray)){//利用画笔填充当前行
e.Graphics.FillRectangle(brush, e.RowBounds);
//将值重新写回当前行。
❺ DataGridView 选择单元格改变行背景色
设置CellClick就可以了,其实那条语句一起生效,之所以看不出来效果是因为,那一行处于选中状态,版显权示的是默认选择的颜色,当再点另外一行的时,就可以看出背景色已经改变了。
在代码之前添加:
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
另外 click 后,被选中的单元格,还有个 SelectionBackColor 设置。
❻ C#中怎样写语句判定DataGridView中所有行背景颜色都是绿色
for(int i = 0;i<dataGridView1.Rows.Count;i++)
{
if(dataGridView1.Rows[i].DefaultCellStyle.BackColor == System.Drawing.Color.Green)
{
Console.WriteLine("第 {0} 行是绝色",i);
}
}
❼ DataGridView 选择单元格 设置行背景色
rowstyle属性下backcolor选择颜色就行了,不过这样是统一全部是一种,你想要好看点,可以选择样板!在编辑列那里有自动套用格式,那里选择样板!
❽ DataGridView选中行的背景色如何去掉
private void dataGridView1_RowPrePaint(object sender, e){if (e.RowIndex = dataGridView1.Rows.Count - 1)return;DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];try{//dgr.Cells[0]是当前性别列的索引值,用以确定判断哪一列的值
if (dgr.Cells[0].Value.ToString() == 男){//定义画笔,使用颜色是深灰版。
using (SolidBrush brush = new SolidBrush(Color.DarkGray)){//利用画笔填充权当前行
e.Graphics.FillRectangle(brush, e.RowBounds);
//将值重新写回当前行。
❾ datagridview背景色
你只要在DataGridView的DataSourceChanged和Sorted事件里循环判断一下符合条件的行改变它的样式就行了 代码如下 private void Form1_Load(object sender, EventArgs e)
{
DataTable dataTable = new DataTable();
dataTable.Columns.AddRange(
new DataColumn[] {
new DataColumn("姓名"),
new DataColumn("性别")
});
dataTable.Rows.Add(new object[]{"AAA","男"});
dataTable.Rows.Add(new object[] { "BBB", "女" });
dataTable.Rows.Add(new object[] { "CCC", "男" });
dataTable.Rows.Add(new object[] { "DDD", "男" });
dataGridView1.DataSource = dataTable;
} private void dataGridView1_DataSourceChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (item.Cells["性别"].Value as string == "女")
{
item.DefaultCellStyle.BackColor = Color.Red;
}
}
} private void dataGridView1_Sorted(object sender, EventArgs e)
{
dataGridView1_DataSourceChanged(null,null);
}
❿ 如何设置datagridview标题行的背景颜色
设置DataGridView.ColumnHeaderDefaultCellStyle的BackColor属性会发现没有效果。这是因为在启动了可视样式的时候,BackColor和ForeColor的值会被忽略。要解专决很简单:属datagridview1.EnableHeadersVisualStyles = false;获取或设置一个值