[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查询后的结果 ...
随机推荐
- codeforces 675D D. Tree Construction(线段树+BTS)
题目链接: D. Tree Construction D. Tree Construction time limit per test 2 seconds memory limit per test ...
- 使用开源库MagicalRecord操作CoreData
1. 将 MagicalRecord 文件夹拖入到工程文件中,引入 CoreData.frame 框架 2. 在 .pch 文件中引入头文件 CoreData+MagicalRecord.h 注: ...
- NodeJS学习之网络操作
NodeJS -- 网络操作 使用NodeJS内置的http模块简单实现HTTP服务器 var http = require('http'); http.createServer(function(r ...
- NSString字符操作
1.常用创建初始化方法 1.NSString *string0 = @"string"; 2.NSString *string1 = [NSString stringWithFor ...
- ASP.NET MVC自定义路由 - 实现IRouteConstraint限制控制器名(转载)
自定义约束前 namespace MvcApplication2 { public class RouteConfig { public static void RegisterRoutes(Rout ...
- 20141211—C#面向对象,封装
封装 一个private 的变量.在变量名上右键-重构-封装字段 小建议:在创建封装字段的时候,在名字前加 “_”用以区分. 封装时,下划线会自动去除 点击确定后: 应用: 赋值的时候走 set 取值 ...
- php折线图 布局图
例子1: 1 <?php require_once("../conf.php"); ?> <!DOCTYPE HTML> <html> < ...
- 【leetcode】368. Largest Divisible Subset
题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, S ...
- zz 如何在Linux下创建与解压zip, tar, tar.gz和tar.bz2文件
January 2nd, 2009 at 10:31 pm Linux 解压, Linux, tar, tar.bz2, tar.gz, tgz, zip, 压缩, 打包, 文档 这么多年来,数据压缩 ...
- C++ 11 之Lambda
1.Lambda表达式来源于函数式编程,说白就了就是在使用的地方定义函数,有的语言叫“闭包”,如果 lambda 函数没有传回值(例如 void ),其回返类型可被完全忽略. 定义在与 lambda ...