请教:如题,有没有相关的,或可否实现?
解决方案 »
- FTP上传
- 给串口发送一条命令,如何验证命令是否执行成功,serialport
- 急!!SQL加字段说明时,怎样使说明换行显示?
- 在一个windows窗体中如何让调用另外一个窗体的控件属性?
- 获得界面上picturebox指针
- 如何讀取ACCESS數據庫的表名和字段名..............散分
- 请问,那为高手可以提供POP的BASE64解码和 提取附件的方法
- 跪求:因为书写格式不规范,2个月的心血被列为垃圾代码,请问哪位绝顶高人,有没有好工具可以让代码自动规范呀???
- 怎样指定程序使用的.net framework版本?
- 能否预测一下子性能啊?
- C#窗口程序连接Access数据库的Insert语句出了问题
- VS2008+SQL2005开发的程序,如果数据库转移到SQL2000上会不会出问题
int RowNum, Brush BackBrush, Brush ForeBrush,
bool AlignToRight)
{
bool bdel = (bool) GetColumnValueAtRow(Source, RowNum); if(bdel == true)
BackBrush = Brushes.Coral;
else
BackBrush = Brushes.White; g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height); System.Drawing.Font font = new Font(System.Drawing.FontFamily.GenericSansSerif,
(float)8.25 );
g.DrawString( bdel.ToString(), font, Brushes.Black, Bounds.X, Bounds.Y);
}private void CreateDataGridStyle()
{
DataGridColumnStyle GridDelColumn;
DataGridColumnStyle GridSeqStyle;
DGStyle = new DataGridTableStyle(); //DGStyle is DataGridTableStyle DGStyle.MappingName = "Table1"; GridSeqStyle = new DataGridTextBoxColumn();
GridSeqStyle.MappingName = "Column1";
GridSeqStyle.HeaderText = "Column1";
GridSeqStyle.Width = 100;
DGStyle.GridColumnStyles.Add(GridSeqStyle); PropertyDescriptorCollection pcol = this.BindingContext[myDataSet,
"Table1"].GetItemProperties(); GridDelColumn = new ColumnStyle(pcol["Table1"]);
GridDelColumn.MappingName = "Column2";
GridDelColumn.HeaderText = "Column2";
GridDelColumn.Width = 100;
DGStyle.GridColumnStyles.Add(GridDelColumn); DGStyle.AllowSorting = true;
DGStyle.RowHeadersVisible = true;
}完成之后添加到DataGrid中CreateDataGridStyle();
myDataGrid.TableStyles.Add(DGStyle);myDataGrid.SetDataBinding(myDataSet,"Table1");文章原地址:http://www.codeproject.com/KB/cs/custom_datagridcolumnstyl.aspx可以看看
列动态生成可使用ITemplate
RowCreated 中设置
e.Row.BackColor = System.Drawing.Color.Red;
变色不是ROW变色,而是单元格可以变色(背景色可以自己设置,也就是说一行可能有多个颜色)
但设置每个单元格不同颜色还是可以的,在RowCreated事件中进行,以下是设置三行三列不同的颜色:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCellCollection cells = e.Row.Cells;
if (e.Row.RowIndex == 0)//第1行
{
for (int i = 0; i < cells.Count; i++)
{
if (i == 0)//第1单元格
cells[i].BackColor = System.Drawing.Color.Red;
else if (i == 1)//第2单元格
cells[i].BackColor = System.Drawing.Color.Green;
else//其它单元格
cells[i].BackColor = System.Drawing.Color.Blue;
}
}
else if (e.Row.RowIndex == 1)//第2行
{
for (int i = 0; i < cells.Count; i++)
{
if (i == 0)
cells[i].BackColor = System.Drawing.Color.Green;
else if (i == 1)
cells[i].BackColor = System.Drawing.Color.Blue;
else
cells[i].BackColor = System.Drawing.Color.Red;
}
}
else//其他行
{
for (int i = 0; i < cells.Count; i++)
{
if (i == 0)
cells[i].BackColor = System.Drawing.Color.Blue;
else if (i == 1)
cells[i].BackColor = System.Drawing.Color.Red;
else
cells[i].BackColor = System.Drawing.Color.Green;
}
}
}