[WinForm]- 设置DataGridView单元格内根据不同值显示图片
首先设置要显示图片的列
DataGridViewImageColumn status = new DataGridViewImageColumn();
status.DisplayIndex = ;
status.HeaderText = "Status";
status.DataPropertyName = "IsPass";
status.ImageLayout = DataGridViewImageCellLayout.Zoom;
dgvTestSteps.Columns.Insert(, status);
添加DataGridView事件CellFormatting
dgvTestSteps.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvTestSteps_CellFormatting);
在事件内添加根据数据值显示不同图片的方法,判断列的地方有很多条件可以进行判断,但是通过Index感觉是最不可取的,通过HeadName也会有上下对不上的情况。
void dgvTestSteps_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dgvTestSteps.Columns[e.ColumnIndex].HeaderText.Equals("Status"))
{
if (e.Value == null)
{
return;
}
StepType type = (StepType)Enum.Parse(typeof(StepType), e.Value.ToString(), true);
switch (type)
{
case StepType.Success:
e.Value = Resources.check;
break;
case StepType.Fail:
e.Value = Resources.close_delete;
break;
case StepType.Block:
e.Value = Resources.attention;
break;
case StepType.NoRun:
e.Value = Resources.green_ball;
break;
}
}
}
[WinForm]- 设置DataGridView单元格内根据不同值显示图片的更多相关文章
- 设置DataGridView单元格的文本对齐方式
实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性 //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...
- winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难
// winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...
- Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)
设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);
- winform的datagridview单元格输入限制和右键单击datagridview单元格焦点跟着改变
在datagridview的EditingControlShowing事件里面添加代码: if (this.dgv_pch.Columns[dgv_pch.CurrentCell.ColumnInde ...
- 设置dataGridView单元格颜色、字体、ToolTip、字体颜色
this.dataGridView3.Rows[e.RowIndex].Cells["你的那个要判断的列名"].Style.BackColor = Color.MediumPurp ...
- WinForm - 格式化DataGridView单元格数据
效果: 代码: /// <summary> /// 格式化数据 /// </summary> private void dataGridView1_CellFormatting ...
- Winform Datagridview 单元格html格式化支持富文本
Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...
- WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序
TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...
- Excel自文本导入内容时如何做到单元格内换行
前言:今天在处理数据的时候,在数据库中用到了\n换行符号,目的是在同表格内做到数据多行显示,比如 字段名1 字段名2 字段名3 1 数据一行 数据二行 数据三行 例子是在sql查询后的结果 ...
随机推荐
- 关于使用Exception的一点心得
毫无疑问,Exception有很多优点.查看任何一本面向对象的书籍,都会提到异常相对于返回值标记状态的不足以及避免错误导致程序崩溃的问题.看起来是很好的,用起来也是很好的.可是这么多年过去了,异常用的 ...
- hdu 3062 2-SAT问题
思路:裸的2-SAT. #include<map> #include<set> #include<cmath> #include<queue> #inc ...
- 转: adroid音视延迟 10ms的原因与解答
https://github.com/hehonghui/android-tech-frontier/blob/master/issue-9/Android%2010ms%E9%97%AE%E9%A2 ...
- for in
1 for in 循环如果遍历的是数组 那么 i 就是数组的索引值 var x; var person=[456,"qwe",890]; for (x in person) ...
- html5+css3第一屏滚屏动画效果
详细内容请点击 在线预览立即下载 html5+css3第一屏滚屏动画效果. 转载自:http://tympanus.net/codrops/2014/05/22/inspiration-for-art ...
- 北大ACM(POJ1006-Biorhythms)
Question:http://poj.org/problem?id=1006 问题点:孙子定理 Memory: 248K Time: 0MS Language: C++ Result: Accept ...
- javascript 操作复选框无效
<script type="text/javascript"> // 操作checkbox复选框按钮 var inputs = $('#article_list').f ...
- RSA 加解密
#region RSA public static byte[] GetBytes(String num) { BigInteger n = ); String s = n.ToString(); & ...
- 使用FlashFXP V3.8烈火汉化绿色版软件连接Linux
使用FlashFXP V3.8烈火汉化绿色版软件连接Linux 单击右上角的小闪电图标: 特别注意:出于安全考虑,FTP默认禁止使用root账号登陆Linux主机,必须使用除root用户以外的其他用户 ...
- 【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转
//绕着与axis平行的任意轴旋转 void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 ...