首先设置要显示图片的列

  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单元格内根据不同值显示图片的更多相关文章

  1. 设置DataGridView单元格的文本对齐方式

    实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性     //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...

  2. winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难

    // winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...

  3. Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)

    设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);

  4. winform的datagridview单元格输入限制和右键单击datagridview单元格焦点跟着改变

    在datagridview的EditingControlShowing事件里面添加代码: if (this.dgv_pch.Columns[dgv_pch.CurrentCell.ColumnInde ...

  5. 设置dataGridView单元格颜色、字体、ToolTip、字体颜色

    this.dataGridView3.Rows[e.RowIndex].Cells["你的那个要判断的列名"].Style.BackColor = Color.MediumPurp ...

  6. WinForm - 格式化DataGridView单元格数据

    效果: 代码: /// <summary> /// 格式化数据 /// </summary> private void dataGridView1_CellFormatting ...

  7. Winform Datagridview 单元格html格式化支持富文本

    Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...

  8. WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序

    TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...

  9. Excel自文本导入内容时如何做到单元格内换行

    前言:今天在处理数据的时候,在数据库中用到了\n换行符号,目的是在同表格内做到数据多行显示,比如  字段名1  字段名2  字段名3  1 数据一行 数据二行 数据三行 例子是在sql查询后的结果  ...

随机推荐

  1. angularJs中筛选功能-angular.filter-1

    技术分享:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/angular-filter-learn-1/ 以下介绍为自己在使用ang ...

  2. C# struct

    很困惑,为什么C#会有struct 这样一个关键字.虽然我用C#几年了,但绝少用到此关键字.我在相关书籍上学习C#的时候,看到过struct内容——但C#并不是我的第一入门语言,所以没有那么细致的学习 ...

  3. 六.CSS浮动与清除

    浮动 把元素从常规文档流中取出.是元素脱离常规文档流 浮动的作用: ①实现文本绕排图片效果 ②让原本在上下方向上堆叠的块级元素可以变成左右并列,从而实现多栏布局 文本绕排图片 首先HTML代码如下 & ...

  4. 二维码zxing源码分析(四)wifi部分

    前三个部分的地址是:ZXING源码分析(一)CAMERA部分  . zxing源码分析(二)decode部分.zxing源码分析(三)result.history部分 前面三篇文章基本上已经把zxin ...

  5. Android&iOS视频直播之旅

    现在的移动互联网时代,大家的网速真是越来越快,高带宽的WIFI和覆盖率极大的4G,4G+把手机观看视频直播推上了风口浪尖,越来越多的应用在玩手机视频直播,我们做的应用里也要嵌入视频直播. 这篇文章里我 ...

  6. Struts2_概述

  7. SQL server自定义函数实例

    create function dbo.t_bh (@str varchar(20)) returns varchar(20) as begin declare @bh varchar(20),@le ...

  8. WIN7实用的运行命令

    运行命令主要是DOS操作系统的运行方式.为方便用户的操作,微软公司将一些常用的命令,如DIR,CD等命令全部集成在系统里面:存放这些内部命令的文件是“Command”(文件后缀.com).它与IO.s ...

  9. js 调用php代码

    <?php $test = "var a = ".$_GET['test'].";"; ?> <mce:script type="t ...

  10. lamp环境的配置

    转载请注明原作者出处 write by xiaoyang 一.    先决条件 系统:RHEL Server6.5 工具:MySQL.MySQL Server.PHP.PHP-MySQL.HTTPD等 ...