AlternatingBackColor属性!可以在属性设计器中设置,代码设置如下,给个例子:
private void inidataGrid(DataView dv)
{
DataGridTextBoxColumn TxtCol =new DataGridTextBoxColumn();
dv.AllowNew=false;
dv.AllowDelete=false;
this.dG1.TableStyles.Clear();
this.dG1.DataSource=dv;
DataGridTableStyle ts= new DataGridTableStyle();
ts.MappingName ="insurance";
ts.AlternatingBackColor=System.Drawing .Color.Bisque;
TxtCol.MappingName ="name";
TxtCol.HeaderText ="名称";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="specify";
TxtCol.HeaderText ="规格";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="yearnumber";
TxtCol.HeaderText ="年限";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="sumorwin";
TxtCol.HeaderText ="分类";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="bookdate";
TxtCol.HeaderText ="最后领用日期";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="signature";
TxtCol.HeaderText ="签字";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); dG1.TableStyles.Add(ts); }
private void inidataGrid(DataView dv)
{
DataGridTextBoxColumn TxtCol =new DataGridTextBoxColumn();
dv.AllowNew=false;
dv.AllowDelete=false;
this.dG1.TableStyles.Clear();
this.dG1.DataSource=dv;
DataGridTableStyle ts= new DataGridTableStyle();
ts.MappingName ="insurance";
ts.AlternatingBackColor=System.Drawing .Color.Bisque;
TxtCol.MappingName ="name";
TxtCol.HeaderText ="名称";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="specify";
TxtCol.HeaderText ="规格";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="yearnumber";
TxtCol.HeaderText ="年限";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="sumorwin";
TxtCol.HeaderText ="分类";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="bookdate";
TxtCol.HeaderText ="最后领用日期";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); TxtCol=new DataGridTextBoxColumn();
TxtCol.MappingName ="signature";
TxtCol.HeaderText ="签字";
TxtCol.Width =100;
TxtCol.NullText="";
TxtCol.ReadOnly=true;
TxtCol.TextBox.TabStop=true;
ts.GridColumnStyles.Add(TxtCol); dG1.TableStyles.Add(ts); }
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q745q
-------------
继承DataGrid,重写paint事件,使用SetFontColor代理,根据返回的Color
str = Convert.ToString(this[row,i]);
x = this.GetCellBounds(row,i).Left;
e.Graphics.DrawString(str, this.Font, new SolidBrush(ea.FontColor),x,y);
使用自己定制的DataGrid控件,在OnSetFontColor事件中判断当前行的成绩,并返回Color。
-------------
如果仅仅是改变分数的颜色,可能实现容易一点
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
protected override void Paint(...)
判断当前值画一下就可以了。
重画吧!
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxwlkWalkthroughUsingCustomActionToCreateDatabaseDuringInstallation.asp看完后,你就能深入地掌握 DataGrid 的扩展方法了。
用第二个方法改变单个单元格的文字颜色没有问题,可是这个一行的 ,不是不会啊,能不能讲具体点啊
e.Item.Cells[5].Style.Add("font-weight", "bold");
e.Item.Cells[5].ForeColor = System.Drawing.Color.Red;
e.Item.BackColor = System.Drawing.Color.AliceBlue;
|
UDGEditableContainer UDGInactiveContainer UDGReversalContainerUDGEditableContainer是可编辑的。
UDGInactiveContainer是不可编辑的,支持多选。
UDGReversalContainer是反转的。
他们都从UDGStyleContainer类继承。UDGStyleContainer用于设置DataGrid的风格。
在UDGStyleContainer中实现SetRowColor(int row),修改某一行的颜色。一些实现细节请参考:http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp我已经把这些类编译成dll了。
准备4月底的时候写一下帮助文件,把它发布出给各位网友。