wince下DataGrid如何给指定行上颜色(C#)

sxhmylove 2014-07-10 11:07:31
wince下DataGrid如何给指定行上颜色(C#)
分不多,各位大神帮帮忙啊,弄了好几天了
...全文
407 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
a312637477 2014-09-03
  • 打赏
  • 举报
回复
所有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); } } } }
sxhmylove 2014-07-12
  • 打赏
  • 举报
回复
能来点靠谱的否,是wince的datagrid
exception92 2014-07-11
  • 打赏
  • 举报
回复
引用 3 楼 ningxin_2670947873 的回复:
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。
ningxin_2670947873 2014-07-11
  • 打赏
  • 举报
回复
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); }
sxhmylove 2014-07-10
  • 打赏
  • 举报
回复
网上的能找到的都弄过了,还是没玩出来 能不能给个例子呢
exception92 2014-07-10
  • 打赏
  • 举报
回复
好像不可以设置。 给个链接, http://bbs.csdn.net/topics/390799940

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧