[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查询后的结果 ...
随机推荐
- Python(2.7.6) 标准日志模块 - Logging Configuration
除了使用 logging 模块中的 basicConfig 方法配置日志, Python 的 logging.config 模块中, dictConfig 和 fileConfig 方法分别支持通过字 ...
- Android应用数据备份
在Android上可以很方便地管理数据备份,那些不慎丢失设备的用户会对该功能感激不尽.备份数据会很安全地存储在云端,并且只在具有相同谷歌ID设备上恢复数据. 下面是典型的AndroidManifest ...
- 【Cocos2d入门教程三】HelloWorld之一目了然
什么程序都是从HelloWorld先开始.同样Cocos2d-x我们先从HelloWorld进行下手.下面是HelloWorld的运行完成图: 建立好的Cocos游戏项目中会有两个比较常用接触的文件夹 ...
- SQL Server 发布订阅 发布类型详解
MicrosoftSQL Server 提供了三种复制类型. 每种复制类型都适合于不同应用程序的要求. 根据应用程序需要,可以在拓扑中使用一种或多种复制类型: 快照复制 事务复制 合并复制 为了帮助您 ...
- Android之画廊点击内容显示
package com.example.Gallery; import com.example.Gallery.R; import android.os.Bundle; import android. ...
- 遇到的 autoresizingMask 相关的问题
1.前言 当一个控件设置好 frame,然后出现会 frame 显示不准或是跟随父控件的变化而变化了,你就要考虑是否是 autoresizing 的问题了 当在 xib 中布局时,报 NSAutore ...
- OpenStack 加入新的节点,创建虚拟机失败的问题
最开始做OpenStack的时候,由于只是为了部署测试用,因此将所有的部分都装在一台单网卡的机器上,费了九牛二虎之力终于部署成功,其中最主要的两块问题出现在以下两个方面: 1:nova.neutron ...
- 远程连接postgres,出现server doesnt listen
已修改pg_hdb.conf中的 # IPv4 local connections: host all all 127.0.0.1/32 ...
- 记一次linux samba服务问题调试
linux下samba服务加入windows域控后,samba共享名与合法用户名不应一致,否则无法访问此共享.
- Cadence Allegro小技巧-从外部文本文件添加文本
菜单“Add->Text”,然后在右侧Options栏设置好合适的Class and Subclass,Text block,然后在布板界面上点击鼠标左键,设置起始点,接着点击鼠标右键,在弹出的 ...