转自 
https://maodaili.de/mao.php?u=a%2FMrbEvUE8PnCuc7FrhJi0Rqd3kmOBHPZUbcJ1c2hbJUK0RYWpAf4lhIOddItP%2BKI2z5PZEiVpY%3D&b=15

DataGridView中DataGridViewComboBoxColumn的一些相关应用(一)让其值改变时触发事件

分类: Form2008-07-23 23:27 2451人阅读 评论(4) 收藏 举报
 今天在csdn回一个帖子的时候看到一个DataGridView问题,需要触发DataGridViewComboBoxCell中的事件才能够解决.

打开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的一些相关应用(一)让其值改变时触发事件-转的更多相关文章

  1. input中的内容改变时触发的事件

    input中的内容改变时触发的事件 1. onchange事件与onpropertychange事件的区别: onchange事件在内容改变(两次内容有可能相等)且失去焦点时触发:onproperty ...

  2. 当input中的内容改变时触发的事件

    当input中的内容改变时触发的事件 1 $('#id').bind('input propertychange', function() { //处理内容 } 循环js事件 $(document). ...

  3. datagridview中combobox类型的cell选中一个下拉列表之后,立即生效的事件

    public event EventHandler CurrentCellDirtyStateChanged 当单元格的内容已更改,但更改尚未保存时,该单元格将标记为已修改. 此事件通常会在以下情况下 ...

  4. 使用Jquery解决Asp.Net中下拉列表值改变后访问服务器刷新界面。

    使用DropDownList控件时,改变选项时,获取服务端数据库数据并刷新界面数据. 1. 绑定DropDownList控件SelectedIndexChanged事件. 2. AutoPortBac ...

  5. winfrom datagridview中DataGridViewTextBoxColumn的联动处理

    这个问题有两种方法 第一种是用DataGridview中自带的DataGridViewTextBoxColumn 控件,第二种是动态添加combobox控件 方法一: 首先 窗体上拖拽一个 DataG ...

  6. DataGridView中实现checkbox全选的自定义控件

    在DataGridView中实现Checkbox的全选的方法就是在列头画一个checkbox, 并给其一个事件. 这个之前很多blog都有写, 这里就不多废话了,  codeproject上面有示例代 ...

  7. C# winform单元格的formatted值的类型错误 DataGridView中CheckBox列运行时候System.FormatException异常

    在DataGridView手动添加了CheckBox列;在窗体Show的时候,遇到一个错误:错误如下: DataGridView中发生一下异常:System.FormatException:单元格的F ...

  8. DataGridView中的DataGridViewComboBoxColumn 让其值改变联动

    在工作中自己也遇到过这类问题, 最近也有很多人问我这个问题, 就此机会写出来记录一下. 首先,顾名思义,值改变事件我们会想到 dataGridView1_CellValueChanged 这个事件,想 ...

  9. [Winform] DataGridView 中 DataGridViewComboBox 的可编辑

    在 DataGridView 中设置的 DataGridViewComboBox,默认是不可编辑的,即使将其列属性 DisplayStyle 设置成 ComboBox 或其他,也无法编辑: 故作如下处 ...

随机推荐

  1. Centos配置jdk和tomcat环境

    centos java+tomcat环境配置 一.安装java环境 在CentOS7.2上安装jdk1.8(tar.gz安装包),并配置环境变量 jdk安装在/home/soft/jdk1.8.0-1 ...

  2. php用户名密码

    http://112.124.47.59:8090/activity/index/free?mobile=15652701923&tcode=f9380859085200714&s=7 ...

  3. JavaScript实现图片裁剪预览效果~(第一个小玩具)

    感觉开始学习的前一个月真的太不珍惜慕课网的资源了  上面蛮多小玩意真的蛮适合我这样刚入门JavaScript的同学加深使用理解 大概收藏了百来门或大或小的课程  有一个感觉就是学这个真的比光是看书看概 ...

  4. leetcode218

    from heapq import * class Solution: def getSkyline(self, LRH): skyline = [] i, n = 0, len(LRH) liveH ...

  5. Mysql中select的正确姿势

    引言 大家在开发中,还有很多童鞋在写查询语句的时候,习惯写下面这种不规范sql select * from table 而不写成下面的这种规范方式 select col1,col2,...,coln ...

  6. ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(三)加载空间数据

    之前两篇基本上搭好了geodjango开发的环境了,当然你的电脑上肯定要有python和django的环境(这个我就不介绍了,网上一搜一大堆),我自己用的python3.5和django2.0(毕竟2 ...

  7. react-navigation设置navigationOptions中Static中使用 this 的方法

    使用react-navigation时,单页面设置navigationOptions中,进行Static中 调用this 中的方法或值时,需要做如下操作 static navigationOption ...

  8. element el-upload组件获取文件名

    组件的连接:http://element-cn.eleme.io/#/zh-CN/component/upload 需求:点x按钮,获取文件名传到后端服务,把文件从服务器删除 分析: 仔细看文档,会发 ...

  9. 使用linux的shell脚本实现在当前行重复动态显示时间等字符串信息(不另起新行)

    ###本脚本在Suse11sp2当中验证正确 #!/bin/sh )) do echo -ne "\r$(date)" sleep 0.3 done ###关键在 echo 的 & ...

  10. while 循环居然可以用else

    while 循环居然可以用else python 3 while a<50: print a a=a+1 else: print"over."