惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

博客园 - 缤纷夏日

文件分割合并DOS版 安装vs2017后,RDLC 报表定义具有无法升级的无效目标命名空间 frp+TeamViewer 完美解决TeamViewer5分钟商业提醒 TortoiseGit版本库中某个文件显示问号或叹号的问题解决办法 vs2012调试时,抛出异常的等待时间很慢,原来是QQ电脑管家搞的鬼。 wordpress4.4+版本自动生成一个768w像素缩略图的解决办法 vs2012 与 win7 不兼容的问题 c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单。 自制《要塞:十字军东征》无限金钱修改器 ms Sql 数据库出现 “提供的统计信息流已损坏”的解决办法。 C#+Midi 模拟各种乐器演奏 DataGridView 显示和隐藏DataGridViewButtonCell按钮的办法 文件隐藏助手,将一个压缩文件隐藏到图片中 如何让DataGridview控件自动滚动到指定的行或列 为Winform程序中DataGridView控件增加自动显示行号功能 在Excel Vba程序中自制进度条,显示实时进度信息 Winform中的DataGridView控件内容自动保存 地下城守护者2 无限魔法修改器 缤纷影视系统3.0源码开放
如何让DataGridView根据数据“0”或“1”等值显示为“是”或“否”(复选框的使用)
缤纷夏日 · 2011-06-09 · via 博客园 - 缤纷夏日

在数据库中,我们经常用一些简单的数值(如0、1、2等)代表一定含义,如:是/否,男/女,正确/错误,已婚/未婚/离异等。

但在DataGridView控件中如何显示呢?

一种办法是使用 select Case 语句。

二种方法就是使用DataGridView 列定制。

这里主要讲的是第二种方法。

在设置DataGridView列属性时,将ColumnType设置为DataGridViewComboBoxColumn,DisplayStyle设置为Nothing,然后是代码:

在窗体加载过程中录入下列代码:

((DataGridViewComboBoxColumn)gvSaleOrder.Columns["payMode"]).DisplayMember = "text";
            ((DataGridViewComboBoxColumn)gvSaleOrder.Columns["payMode"]).ValueMember = "value";
            DataTable dtPayMode = new DataTable();
            dtPayMode.Columns.Add("text");
            dtPayMode.Columns.Add("value", typeof(byte));
            dtPayMode.Rows.Add(new object[] { "现金", 0 });
            dtPayMode.Rows.Add(new object[] { "刷卡", 1 });
            ((DataGridViewComboBoxColumn)gvSaleOrder.Columns["payMode"]).DataSource = dtPayMode;

这样就可以在对DataGridView绑定数据时,自动根据0或1等状态显示相应的中文了。如下图: