转自 
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. EA Data Modeling 显示别名设置

    1.设置 2.效果 

  2. ndoejs处理编码的爬虫

    var express=require('express');var http=require('http');var cheerio=require('cheerio');var fs=requir ...

  3. 浅析STM32之usbh_def.H

    [温故而知新]类似文章浅析USB HID ReportDesc (HID报告描述符) 现在将en.stm32cubef1\STM32Cube_FW_F1_V1.4.0\Middlewares\ST\S ...

  4. 排序NB三人组

    排序NB三人组 快速排序,堆排序,归并排序 1.快速排序 方法其实很简单:分别从初始序列“6  1  2 7  9  3  4  5 10  8”两端开始“探测”.先从右往左找一个小于6的数,再从左往 ...

  5. ORM 的基本操作

    https://www.cnblogs.com/sss4/p/7070942.html

  6. django403错误(转)

    原文:http://blog.sina.com.cn/s/blog_60ccc6e101011ku0.html 处理过程 1.按提示及google结果修改setting.py,在MIDDLEWARE_ ...

  7. Linux命令:sshpass

    sshpass介绍 sshpass是一款凡是为凡是使用ssl方式访问的操作提供一个免输入密码的非交互式操作,以便于在脚本中执行ssl操作,如ssh,scp等.sshpass是一家以色列公司Lingnu ...

  8. Graylog日志管理系统---搜索查询方法使用简介

    Elasticsearch 是一个基于 Lucene 构建的开源.分布式.提供 RESTful 接口的全文搜索引擎 一.Search页面的各位置功能介绍: 1.日志搜索的时间范围 为了使用方便,预设有 ...

  9. Linux删除ORACLE数据库用户失败提示ORA-01940解决方法

    操作环境 SuSE11+Oracle11gR2 问题现象 删除ORACLE数据库用户失败,提示ORA-01940: cannot drop a user that is currently conne ...

  10. Myeclipse2017 安装反编译插件和SVN插件

    亲测有效 2018年1月22日10:36:33 https://www.cnblogs.com/liuyk-code/p/7519886.html