转自 
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. PropertiesUtils

    package com.icil.elsa.subscribe.milestone.common.utils; import java.io.BufferedInputStream; import j ...

  2. PHP数据库基于PDO操作类(mysql)

    这是网上找的关于Mysql的操作类,非常适合初学者使用 <?php class Mysql { protected static $_dbh = null; //静态属性,所有数据库实例共用,避 ...

  3. Spring Cloud(2)A Eureka server端 服务注册建立

    1. 父项目pom <dependency> <groupId>org.springframework.cloud</groupId> <artifactId ...

  4. 【JEECG技术文档】Online唯一校验使用说明

    1.功能介绍 配置了唯一校验的字段,在录入和编辑页面中,动态查询用户输入值是否存在校验. 要使用online唯一校验功能必须先在online表单开发中配置唯一字段的校验方式为唯一校验. 2.配置唯一校 ...

  5. 原生java读取存储为xml格式的数据,并存储到java bean里

    一.举例读取的文件为:X-bond可交易债券信息_20180917.xml <?xml version="1.0" encoding="UTF-8"?&g ...

  6. iOS设计标注处理方法

    如果设计只给3x的设计图 在做2x适配时有几种处理方法: 按逻辑像素,大小不变,比如3x手机上一张图的逻辑像素设为24x24point,那么2x手机上这张图的大小也设为24x24point,一般适用于 ...

  7. C++中类的多继承

    在写这一主题的文章之前,在网上找到一篇很非常好的文章C++之继承与多态.就没有必要做重复造轮子的事件了,那就从这篇文章开始吧! 在c++中一个类可以从多个基类中派生(即可以有多个父类),这就是多继承. ...

  8. log4j 文件配置

    //log4j配置日志文件输出到磁盘一天一个 log4j.appender.File=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.F ...

  9. 22.struts2-拦截器.md

    目录 1.执行的流程时序图 1.执行的流程时序图 回顾: Struts配置: * 通配符.动态方法调用 * 全局跳转配置.配置的默认值.常量配置 * Struts核心业务 * 请求数据的自动封装 (p ...

  10. python类中方法加单下划线、双下划线、前后双下滑线的区别

    首先看一段代码: class Foo(): def __init__(self): print "__init__ method" def public_method(self): ...