首先设置要显示图片的列

  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. CentOS6.5下用yum安装 git

    cd /etc/yum.repos.d/ wget http://geekery.altervista.org/geekery-el6-x86_64.repo 2. 到http://packages. ...

  2. 2014年互联网IT待遇【转载】

    2014年互联网IT待遇[转载] 一.民企 1.百度 13k*14.6,special 14~17k*14.6 开发类 13K*14.6    (2014) 测试类.前端类 12K*14.6    ( ...

  3. Table of Contents - Redis

    Getting Started 安装配置环境 Redis 命令 Keys Strings Lists Hashs Sets Sorted Sets Transactions Connection Se ...

  4. c# 生成项目或重新生成项目时报“Project not selected to build for this solution configuration”之解决办法

    菜单->生成->配置管理器->给要生成的项目打钩

  5. git基础入门之常用命令操作

    本内容参考:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 初学,有什么不对的地方 ...

  6. 用宏定义封装LoadLibrary,方便的动态加载dll

    同学们动态加载dll的时候是不是感觉挺麻烦的,每次都::LoadLibrary,::GetProcAddress,还要typedef一堆函数.最近闲来无聊,用宏封装了一下,可以少写不少代码,用来也挺方 ...

  7. Cocos2d-JS中的cc.LabelTTF

    cc.LabelTTF是使用系统中的字体,它是最简单的标签类.cc.LabelTTF类图如下图所示,可以cc.LabelTTF继承了cc.Node类,具有cc.Node的基本特性. LabelTTF类 ...

  8. UI4_LabelChess

    // // AppDelegate.m // UI4_LabelChess // // Created by zhangxueming on 15/6/29. // Copyright (c) 201 ...

  9. Mac下github的使用

    新建github账户   新建Repository,如下图:   建立连接github的秘钥 打开mac的shell cd ~ mkdir .ssh cd .ssh ssh-keygen -t rsa ...

  10. mongodb gdal 矢量数据格式驱动

    写了个mongodb的gdal driver,放在了github上,如果你需要,欢迎加入mongogis group. 直接的效果是使得QGIS, GeoServer, MapServer, ArcG ...