DataGridView中DataGridViewComboBoxColumn的一些相关应用(一)让其值改变时触发事件-转
DataGridView中DataGridViewComboBoxColumn的一些相关应用(一)让其值改变时触发事件
打开vs试了下没有找到能直接触发DataGridViewComboBoxCell中combobox的值改变的事件,郁闷了半天,仔细看MSDN上有解决示例,都怪自己没有仔细看:
首先需要触发第一个事件:CurrentCellDirtyStateChanged
并且在事件中调用DataGridView.CommitEdit 方法 [关于CommitEdit MSDN解释如下:将当前单元格中的更改提交到数据缓存,但不结束编辑模式。 ]
这样我们关心的那个事件CellValueChanged就能够被顺利触发了
调用下MSDN上面对这个解决方式所提供的源码仅供参考:)
// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
} // If a check box cell is clicked, this event handler disables
// or enables the button in the same row as the clicked cell.
public void dataGridView1_CellValueChanged(object sender,
DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "CheckBoxes")
{
DataGridViewDisableButtonCell buttonCell =
(DataGridViewDisableButtonCell)dataGridView1.
Rows[e.RowIndex].Cells["Buttons"]; DataGridViewCheckBoxCell checkCell =
(DataGridViewCheckBoxCell)dataGridView1.
Rows[e.RowIndex].Cells["CheckBoxes"];
buttonCell.Enabled = !(Boolean)checkCell.Value; dataGridView1.Invalidate();
}
}
DataGridView中DataGridViewComboBoxColumn的一些相关应用(一)让其值改变时触发事件-转的更多相关文章
- input中的内容改变时触发的事件
input中的内容改变时触发的事件 1. onchange事件与onpropertychange事件的区别: onchange事件在内容改变(两次内容有可能相等)且失去焦点时触发:onproperty ...
- 当input中的内容改变时触发的事件
当input中的内容改变时触发的事件 1 $('#id').bind('input propertychange', function() { //处理内容 } 循环js事件 $(document). ...
- datagridview中combobox类型的cell选中一个下拉列表之后,立即生效的事件
public event EventHandler CurrentCellDirtyStateChanged 当单元格的内容已更改,但更改尚未保存时,该单元格将标记为已修改. 此事件通常会在以下情况下 ...
- 使用Jquery解决Asp.Net中下拉列表值改变后访问服务器刷新界面。
使用DropDownList控件时,改变选项时,获取服务端数据库数据并刷新界面数据. 1. 绑定DropDownList控件SelectedIndexChanged事件. 2. AutoPortBac ...
- winfrom datagridview中DataGridViewTextBoxColumn的联动处理
这个问题有两种方法 第一种是用DataGridview中自带的DataGridViewTextBoxColumn 控件,第二种是动态添加combobox控件 方法一: 首先 窗体上拖拽一个 DataG ...
- DataGridView中实现checkbox全选的自定义控件
在DataGridView中实现Checkbox的全选的方法就是在列头画一个checkbox, 并给其一个事件. 这个之前很多blog都有写, 这里就不多废话了, codeproject上面有示例代 ...
- C# winform单元格的formatted值的类型错误 DataGridView中CheckBox列运行时候System.FormatException异常
在DataGridView手动添加了CheckBox列;在窗体Show的时候,遇到一个错误:错误如下: DataGridView中发生一下异常:System.FormatException:单元格的F ...
- DataGridView中的DataGridViewComboBoxColumn 让其值改变联动
在工作中自己也遇到过这类问题, 最近也有很多人问我这个问题, 就此机会写出来记录一下. 首先,顾名思义,值改变事件我们会想到 dataGridView1_CellValueChanged 这个事件,想 ...
- [Winform] DataGridView 中 DataGridViewComboBox 的可编辑
在 DataGridView 中设置的 DataGridViewComboBox,默认是不可编辑的,即使将其列属性 DisplayStyle 设置成 ComboBox 或其他,也无法编辑: 故作如下处 ...
随机推荐
- hive grouping sets 实现原理
先下结论: 看了hive 1.1.0 grouping sets 实现(从源码及执行计划都可以看出与kylin实现不一样),(前提是可累加,如sum函数)他并没有像kylin一样先按照group by ...
- tomcat及nginx相关,格式化输出,配置及日志解析
1.https://www.cnblogs.com/jingmoxukong/p/8258837.html?utm_source=gold_browser_extension Tomcat ...
- spark 常用技巧总结2
zip拉链操作 def zip[U](other: org.apache.spark.rdd.RDD[U])(implicit evidence$10: scala.reflect.ClassTag[ ...
- 汉诺塔问题python
count = 0def hanoi(n,src,mid,dst): global count if n == 1: print("{}:{}->{}".format(1,s ...
- react-native 插件汇总
部分自己搜集 部分 来自别的网站 第三方路由插件 react-native-router-flux react-native-scrollable-tab-view 选项卡 测滑动菜单 react-n ...
- 爬虫--urllib模块
一.urllib库 概念:urllib是Python自带的一个用于爬虫的库,其主要作用就是可以通过代码模拟浏览器发送请求.其常被用到的子模块在Python3中的为urllib.request和urll ...
- mui 常用手势
一 事件: 点击:1. tap 单击屏幕2. doubletap 双击屏幕长按:1. longtap 长按屏幕2. hold 按住屏幕3.release 离开屏幕滑动:1. swipeleft 向左滑 ...
- guava collection/cache初探
写了上面一篇,看了点eventbus相关的guava代码后,发现里面用到了很多其他guava包里的方法,所以顺着看一下,比如之前用到的map都是guava自己的 Multimap:可以包含有几个重复K ...
- Redis学习笔记一(Redis的详细安装及Linux环境变量配置和启动)
Redis Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 我使用的是下面这个版本: 若没有资源的话,我在 ...
- dependencies与dependencyManagement的区别
1.DepencyManagement应用场景 当我们的项目模块很多的时候,我们使用Maven管理项目非常方便,帮助我们管理构建.文档.报告.依赖.scms.发布.分发的方法.可以方便的编译代码.进行 ...