在DataGrid的ItemDataBound事件里面写:
if((e.Item.Cells[5].Text)=="女")
{
e.Item.BackColor=Color.AliceBlue;
}
上面的意思是说,当DataGrid中第6列的值是“女”时,将这一行的背景色设置为AliceBlue。
if((e.Item.Cells[5].Text)=="女")
{
e.Item.BackColor=Color.AliceBlue;
}
上面的意思是说,当DataGrid中第6列的值是“女”时,将这一行的背景色设置为AliceBlue。
解决方案 »
- 请问高手这中程序的设计思路
- 学习C#
- 请教正则表达式高手,关于aabbcc。
- 关于如何在.net环境中使用asp中的ewebeditor文本编辑器?
- 多线程里如何访问窗体里的控件
- 100分求助:服务器上画面间控制问题
- 2003中怎么不能用System.Web.Mail???(急~急~急~)
- C#新手:我从Delphi看过来!
- 在DataGrid中怎么将列标题设置为居中?
- 高分讨论C#中反射的用法。
- 我连接数据库时,提示这个错误:sa登录失败,未与信任的SERVER\DADI(服务器上的数据库)联接相关联,到底是错在什么地方?
- 为什么结果listBox1中显示的是:System.Data.DataRowView呢?
public class Form1: Form
{
protected DataGrid dataGrid1;
protected DataSet myDataSet;private void PaintCell(object sender, MouseEventArgs e)
{
// Use the HitTest method to get a HitTestInfo object.
DataGrid.HitTestInfo hi;
DataGrid grid = (DataGrid)sender;
hi=grid.HitTest(e.X, e.Y);
// Test if the clicked area was a cell.
if(hi.Type == DataGrid.HitTestType.Cell)
{
// If it's a cell, get the GridTable and ListManager of the
// clicked table.
DataGridTableStyle dgt = dataGrid1.TableStyles[0]; //我自己加的begin myDataSet=bd.LoadBDTableByID("BD200204");
dgt.MappingName="BD200204"; //我自己加的end CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataSet.Tables[dgt.MappingName]];
// Get the Rectangle of the clicked cell.
Rectangle cellRect;
cellRect=grid.GetCellBounds(hi.Row, hi.Column);
// Get the clicked DataGridTextBoxColumn.
MyGridColumn gridCol =(MyGridColumn)dgt.GridColumnStyles[hi.Column];
//上面一句错误,信息“指定的转换无效” // Get the Graphics object for the form.
Graphics g = dataGrid1.CreateGraphics();
// Create two new Brush objects, a fore brush, and back brush.
Brush fBrush = new System.Drawing.SolidBrush(Color.Blue);
Brush bBrush= new System.Drawing.SolidBrush(Color.Yellow);
// Invoke the Paint method to paint the cell with the brushes.
gridCol.PaintCol(g, cellRect, cm, hi.Row, bBrush, fBrush, false);
}
}
}public class MyGridColumn:DataGridTextBoxColumn{
public void PaintCol(Graphics g, Rectangle cellRect,
CurrencyManager cm, int rowNum, Brush bBrush,
Brush fBrush, bool isVisible){
this.Paint(g, cellRect, cm, rowNum, bBrush, fBrush, isVisible);
}
}