winform 制定DataGridViewTextColumn列(更改DataGridView的Cell的状态很有用)
2013-11-19 11:12
295 查看
先自定义一个类 继承DataGridViewTextBoxCell
再自定义一个类 继承DataGridViewColumn
借鉴与:http://www.mianwww.com/html/2009/06/3345.html
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; namespace com.Threes.CustomControl { public class DataGridViewBooleanCell : DataGridViewTextBoxCell { protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // Call the base class method to paint the default cell appearance. base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle, advancedBorderStyle, paintParts); if (value is Boolean) if ((bool)value == true) { graphics.DrawString("Y", cellStyle.Font, new SolidBrush(Color.Blue), cellBounds.X, cellBounds.Y); } else { graphics.DrawString("N", cellStyle.Font, new SolidBrush(Color.Red), cellBounds.X, cellBounds.Y); } else if (value is int) { int v = (int)value; if (v == 1) { graphics.DrawString("男", cellStyle.Font, new SolidBrush(Color.Blue), cellBounds.X, cellBounds.Y); } else if (v == 0) { graphics.DrawString("女", cellStyle.Font, new SolidBrush(Color.Red), cellBounds.X, cellBounds.Y); } else { graphics.DrawString("人妖", cellStyle.Font, new SolidBrush(Color.Green), cellBounds.X, cellBounds.Y); } } } } }
再自定义一个类 继承DataGridViewColumn
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace com.Threes.CustomControl { public class DataGridViewBooleanColumn : DataGridViewColumn { public DataGridViewBooleanColumn() { this.CellTemplate = new DataGridViewBooleanCell(); } } }
借鉴与:http://www.mianwww.com/html/2009/06/3345.html
相关文章推荐
- 用正则表达式提取clob里的文本格式记录集
- JVM指令集
- 运用计划缓冲的建议
- 转 oracle中blob,clob,nclob主要区别是什么?
- 正襟危坐说--操作系统(肆):线程
- SQL分页语句格式
- SUSE syslog-ng 设置
- Win7下使用Xmanager远程管理CentOS6.4操作系统
- mysql 日志 (键人岐)
- 格式化时间日期的函数
- 网页计时器
- IPHONE开发 @synthesize 变量下划线
- 虚拟机大牛RednaxelaFX关于java里面的静态变量、成员变量、局部变量的内存分配
- 深入浅出Swing事件分发线程
- Android学习笔记进阶19之给图片加边框
- DB2 pureXML与其它数据库XML实现技术对比
- Python yield 使用浅析
- jsp连接sqlServer2005 数据库的 解决方案
- 多线程共享一个队列
- windows的iis做后门,隐藏访问,无日志<转>