wince下DataGrid如何给指定行上颜色(C#) datagridwincec# 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好像不可以设置。给个链接,http://bbs.csdn.net/topics/390799940 DataGridWiew选中单元格时整个背景变色实例//绑定显示数据 private void Frm_Main_Load(object sender, EventArgs e) { dgv_Message.DataSource = new List<Fruit>() {//绑定数据集合 new Fruit(){Name="苹果",Price=30}, new Fruit(){Name="橘子",Price=40}, new Fruit(){Name="鸭梨",Price=33}, new Fruit(){Name="水蜜桃",Price=31}}; dgv_Message.Columns[0].Width = 200;//设置列宽度 dgv_Message.Columns[1].Width = 170;//设置列宽度 dgv_Message.SelectionMode = //设置如何选择单元格 DataGridViewSelectionMode.FullRowSelect; dgv_Message.DefaultCellStyle.SelectionForeColor//选中单元格的前景色 = Color.Blue; dgv_Message.DefaultCellStyle.SelectionBackColor//选中单元格的背景色 = Color.LightYellow; }//使用代码编辑器修改此方法的内容。 private void InitializeComponent() { this.dgv_Message = new System.Windows.Forms.DataGridView(); ((System.ComponentModel.ISupportInitialize)(this.dgv_Message)).BeginInit(); this.SuspendLayout(); // // dgv_Message // this.dgv_Message.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgv_Message.Dock = System.Windows.Forms.DockStyle.Fill; this.dgv_Message.Location = new System.Drawing.Point(0, 0); this.dgv_Message.Name = "dgv_Message"; this.dgv_Message.RowTemplate.Height = 23; this.dgv_Message.Size = new System.Drawing.Size(412, 161); this.dgv_Message.TabIndex = 0; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(412, 161); this.Controls.Add(this.dgv_Message); this.Name = "Frm_Main"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "DataGridView选中单元格时整个行背景变色"; this.Load += new System.EventHandler(this.Frm_Main_Load); ((System.ComponentModel.ISupportInitialize)(this.dgv_Message)).EndInit(); this.ResumeLayout(false); } 人家说的是wince 不是WinForm。 能来点靠谱的否,是wince的datagrid 所有DataGrid的数据都和显示都在paint里面画上去.就可以实现颜色了.自己建个类.用来保存DataGrid每一行,每一列的 文本值和颜色值然后刷新时候,直接取类中的值.改变颜色和文本值,则刷新单个框就可以了保存字符和颜色的类 class GridShowArgs { public const int row = 8; public const int col = 10; public Color[,] BackColor = new Color[row, col]; public string[,] BackValue = new string[row, col]; public GridShowArgs() { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { BackColor[i, j] = Color.Red; BackValue[i, j] = "测试"; } } } }实例话一个 GridShowArgs AllGridShow = new GridShowArgs();把文本和颜色画上去private void DataGrid_Paint(object sender, PaintEventArgs e) { DataGrid tmpGrid = (DataGrid)sender; StringFormat sr = new StringFormat(); sr.Alignment = StringAlignment.Center; for (int i = 0; i < tmpGrid.VisibleRowCount; i++)//注意我这里只有8行 { for (int j = 0; j < tmpGrid.VisibleColumnCount; j++)//我只有10行 { if (AllGridShow[tagIndex] != null) { e.Graphics.FillRectangle(new SolidBrush(AllGridShow.BackColor[i, j]), tmpGrid.GetCellBounds(i, j)); e.Graphics.DrawString(AllGridShow.BackValue[i, j], new Font("宋体", 15, FontStyle.Bold), new SolidBrush(Color.Black), tmpGrid.GetCellBounds(i, j), sr); } } } } C#动态创建类型Emit的问题 小谈三层架构 关于DataTable合并的问题 C/S系统 客户端链接数据库 .net前台显示 怎么检验C#中文本框中内容是非数字 如何将dataset数据保存到文本文件,和excel文件中? 搜索文件标题和文件内容 文件问题 listbox框怎样进行数据绑定,通过按钮打开一个新窗体的代码是什么 C#,普通类怎么调用session 关于GBK与UTF-8的汉字转码.
给个链接,
http://bbs.csdn.net/topics/390799940
//绑定显示数据 private void Frm_Main_Load(object sender, EventArgs e)
{
dgv_Message.DataSource = new List<Fruit>() {//绑定数据集合
new Fruit(){Name="苹果",Price=30},
new Fruit(){Name="橘子",Price=40},
new Fruit(){Name="鸭梨",Price=33},
new Fruit(){Name="水蜜桃",Price=31}};
dgv_Message.Columns[0].Width = 200;//设置列宽度
dgv_Message.Columns[1].Width = 170;//设置列宽度 dgv_Message.SelectionMode = //设置如何选择单元格
DataGridViewSelectionMode.FullRowSelect;
dgv_Message.DefaultCellStyle.SelectionForeColor//选中单元格的前景色
= Color.Blue;
dgv_Message.DefaultCellStyle.SelectionBackColor//选中单元格的背景色
= Color.LightYellow;
}
//使用代码编辑器修改此方法的内容。
private void InitializeComponent()
{
this.dgv_Message = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dgv_Message)).BeginInit();
this.SuspendLayout();
//
// dgv_Message
//
this.dgv_Message.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv_Message.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgv_Message.Location = new System.Drawing.Point(0, 0);
this.dgv_Message.Name = "dgv_Message";
this.dgv_Message.RowTemplate.Height = 23;
this.dgv_Message.Size = new System.Drawing.Size(412, 161);
this.dgv_Message.TabIndex = 0;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(412, 161);
this.Controls.Add(this.dgv_Message);
this.Name = "Frm_Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "DataGridView选中单元格时整个行背景变色";
this.Load += new System.EventHandler(this.Frm_Main_Load);
((System.ComponentModel.ISupportInitialize)(this.dgv_Message)).EndInit();
this.ResumeLayout(false); }
就可以实现颜色了.自己建个类.用来保存DataGrid每一行,每一列的 文本值和颜色值
然后刷新时候,直接取类中的值.
改变颜色和文本值,则刷新单个框就可以了保存字符和颜色的类
class GridShowArgs
{
public const int row = 8;
public const int col = 10;
public Color[,] BackColor = new Color[row, col];
public string[,] BackValue = new string[row, col];
public GridShowArgs()
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
BackColor[i, j] = Color.Red;
BackValue[i, j] = "测试";
}
}
}
}
实例话一个
GridShowArgs AllGridShow = new GridShowArgs();
把文本和颜色画上去
private void DataGrid_Paint(object sender, PaintEventArgs e)
{
DataGrid tmpGrid = (DataGrid)sender;
StringFormat sr = new StringFormat();
sr.Alignment = StringAlignment.Center;
for (int i = 0; i < tmpGrid.VisibleRowCount; i++)//注意我这里只有8行
{
for (int j = 0; j < tmpGrid.VisibleColumnCount; j++)//我只有10行
{
if (AllGridShow[tagIndex] != null)
{
e.Graphics.FillRectangle(new SolidBrush(AllGridShow.BackColor[i, j]), tmpGrid.GetCellBounds(i, j));
e.Graphics.DrawString(AllGridShow.BackValue[i, j], new Font("宋体", 15, FontStyle.Bold), new SolidBrush(Color.Black), tmpGrid.GetCellBounds(i, j), sr);
}
}
}
}