控件:DataGridView列类型
DataGridView的列的类型提供有多种,包括有:
(1)DataGridViewTextBoxColumn(文本列,默认的情况下就是这种)
(2)DataGridViewComboBoxColumn(组合框列,名字瞎起的,就是这个功能要用到的列)
(3)DataGridViewLinkColumn(链接列)
(4)DataGridViewButtonColumn(按钮列)
(5)DataGridViewCheckBoxColumn(打钩列)
一、DataGridViewComboBoxColumn
实例:
DataTable dt = DBServiceHelper.businessDbHelper.Fill(UserInfo, "select a.code,a.Name from tequip_ini a where a.equip_type in (1,6) ");
if (dt != null)
{
dataGridViewTextBoxColumn3.DataPropertyName = "code";
dataGridViewTextBoxColumn3.DisplayMember = "name";
dataGridViewTextBoxColumn3.ValueMember = "code";
dataGridViewTextBoxColumn3.DataSource = dt;
}
GrdReadRecord2.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(GrdReadRecord2_EditingControlShowing);
实现每一行的该单元格具有不同的ComboBox项:
private void GrdReadRecord2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
if (GrdReadRecord2.CurrentCell.ColumnIndex == )
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
DataTable dt = DBServiceHelper.businessDbHelper.Fill(UserInfo, " select cast(0 as varchar(200)) as code ,'' as Name UNION ALL select a.code,a.Name from tequip_ini a "+
" left join CardPosItem b on a.PosItem=b.id where a.equip_type in(1,6) and b.id= " + this.GrdReadRecord2.CurrentRow.Cells["ColPostItemID"].Value.ToString());
cb.DataSource = dt;
if (dt != null && dt.Rows.Count > )
cb.SelectedIndex = ;
}
}
}
catch (Exception ex)
{
ListBoxAdd(lHint2, "异常:" + ex.Message.ToString());
}
}
值得注意的是:
每一行单元格绑定的数据必须要存在列的Item内,即是在EditingControlShowing前要先设置DataPropertyName、DisplayMember、ValueMember、DataSource,EditingControlShowing查出的数据必须是DataSource的子集。不然就会认为是错误值,报错。
获取选取值:
获取ValueMember:GrdReadRecord2.Rows[e.RowIndex].Cells[5].Value.ToString();
获取DisplayMember:GrdReadRecord2.Rows[e.RowIndex].Cells[5].EditedFormattedValue.ToString();
控件:DataGridView列类型的更多相关文章
- easyUI的datagrid控件日期列不能正确显示Json格式数据的解决方案
EasyUI是一套比较轻巧易用的Jquery控件,在使用过程中遇到一个问题,它的列表控件——datagrid, 在显示日期列的时候,由于后台返回给页面的数据是Json格式的,其中的日期字段,在后台是正 ...
- C#: 线程间操作无效: 从不是创建控件“dataGridView”的线程访问它
最近在修改自动化小工具,用多线程来解决后台拷贝导致WinForm界面卡死的情况,但是遇到过错:线程间操作无效: 从不是创建控件“dataGridView”的线程访问它. 这是因为在多线程程序中,新创建 ...
- easyUI的datagrid控件日期列格式化
转自:https://blog.csdn.net/idoiknow/article/details/8136093 EasyUI是一套比较轻巧易用的Jquery控件,在使用过程中遇到一个问题,它的列表 ...
- GridView控件隐藏列
GridView隐藏列visible="false" 后你就无法取得这列的值了 下面是迄今为止最简洁的解决方法了. protected void GVList_RowDataBou ...
- C#窗体控件DataGridView常用设置
在默认情况下,datagridview的显示效果: 1.禁用最后一行空白. 默认情况下,最后一行空白表示自动新增行,对于需要在控件中进行编辑,可以保留 ? 1 dataGridView1.AllowU ...
- 控件——DataGridview
控件:DataGridview 用来显示数据, 可以显示和编辑来自多种不同类型的数据源的表格数据. 一.两种显示数据的方式:手动,后台代码 主要通过后台代码:先建立三大类 然后绑定 ...
- asp.net GridView控件的列属性
BoundField 默认的数据绑定类型,通常用于显示普通文本 CheckBoxField 显示布尔类型的数据.绑定数据为TRUE时,复选框数据绑定列为选中状态:绑定数据为FALSE时,则显示未选中状 ...
- 【Winform系列】Winform控件DataGridView添加数据的几种方式
1:直接添加 在控件中设置好每列的名称 例如: DataGridViewRow row = new DataGridViewRow(); int j = dgv.Rows.Add(row); dgv. ...
- 【转】C#控件——DataGridView单元格文本自动换行
源地址:https://www.cnblogs.com/wangshenhe/archive/2012/07/25/2608324.html DataGridView是.NET开发中常用的控件,在开发 ...
- C#遍历窗体所有控件或某类型所有控件
//遍历窗体所有控件, foreach (Control control in this.Controls) { //遍历后的操作... control.Enabled = false; } 遍历某个 ...
随机推荐
- IntegerCache缓存占用堆、栈、常量池的问题,自动拆装箱的基本概念,Integer==int时的问题说明
原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 先普及一个基本概念:Java中基本数据类型的装箱和拆箱操作 自动装箱 在JDK5以后,我们 ...
- babel-loader配置
1.npm i @babel/core.@babel/preset-env.@babel/runtime.@babel/plugin-transform-runtime.@babel/plugin-p ...
- idea的ktorm框架代码生成器插件
*:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...
- [源码分析] 从FlatMap用法到Flink的内部实现
[源码分析] 从FlatMap用法到Flink的内部实现 0x00 摘要 本文将从FlatMap概念和如何使用开始入手,深入到Flink是如何实现FlatMap.希望能让大家对这个概念有更深入的理解. ...
- Building Applications with Force.com and VisualForce (DEV401) 中用到的Recruiting Application介绍
1.Who uses Recruiting Application. 2. Recruiting Application Object Model
- CF 631C report
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
- 使用SpringCloud将单体迁移至微服务
使用SpringBoot构建单体项目有一段时间了,准备对一个老项目重构时引入SpringCloud微服务,以此奠定后台服务能够应对未知的业务需求. 现在SOA架构下的服务管理面临很多挑战,比如面临一个 ...
- python使用镜像源安装库
pip install django -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 豆瓣 :http://pypi.d ...
- js 调用铃声
<audio autoplay="autoplay" id="auto" src=""> </audio> play ...
- 过滤器filter学习进度一
过滤器filter他的理解是: filter是对客户端访问资源的过滤,符合条件放行,不符合条件的不放行,并且可以对目标资源访问的前后进行逻辑处理. 快速入门: 1.编写一个过滤器的类实现filter接 ...