首页 > 其他分享 >DataGridView控件3——常用事件

DataGridView控件3——常用事件

时间:2022-10-30 23:14:13浏览次数:62  
标签:控件 常用 CellContentClick RowIndex 单元格 DataGridView cell 事件 dataGridView2

DataGridView的常用事件:

1、CellClick,CellContentClick,CellDoubleClick

2、CellValueChanged,CurrentCellDirtyStateChanged


 

1、CellChanged事件和CellContentClick事件,功能相似。CellDoubleClick和CellClick区别仅在于单击和双击

其区别在于:

CellChanged事件,点击表格内任意部分即可触发事件。

CellContentClick事件,必须点击到表格内的内容时才能触发事件。

注意,使用CellChanged事件和CellContentClick事件时不能点击表头,会引发异常。

        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                //DataGridViewCell cell = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];//通过行标和列表获得当前单元格
                DataGridViewCell cell = dataGridView2.CurrentCell;//通过CurrentCell属性直接获得当前单元格                
                MessageBox.Show(cell.Value.ToString());
            }
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                //DataGridViewCell cell = dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex];//通过行标和列表获得当前单元格
                DataGridViewCell cell = dataGridView2.CurrentCell;//通过CurrentCell属性直接获得当前单元格                
                MessageBox.Show(cell.Value.ToString());
            }
        }

 

2、单元格的Value属性和FormattedValue属性

 

 

 

 

标签:控件,常用,CellContentClick,RowIndex,单元格,DataGridView,cell,事件,dataGridView2
From: https://www.cnblogs.com/hanzq/p/16842584.html

相关文章

  • Docker常用命令
    Docker常用命令(启动、镜像相关、容器相关、文件拷贝、目录挂载、查看容器IP地址、Docker备份与恢复)......
  • pip常用命令和一些坑
    pip常用命令和一些坑参考pip参考文档和平时遇到的问题。记录常用的命令和遇到的错误。​​pip参考文档​​注意事项下面三点很重要,放在了最前面。如果有多个python版本(比如......
  • [2022.10.30]常用类—Date与DateFormat
    importorg.junit.Test;importjava.util.Date;/*1.用system类中的currentTimeMillis()方法2.java.util.Date类1)两个构造器的使用......
  • wpf利用ReoGrid控件进行Excel表格展示及导出
    Nuget包安装Nuget包管理器直接搜索ReoGrid进行安装,如图   前端根据官方文档(https://reogrid.net/document/installation/)在前端引入命名空间:xmlns:rg="clr-na......
  • kafka常用命令
    相关概念Brokerkafka节点,多个broker组成kafka集群。Topic即主题,kafka通过Topic对消息进行分类,发布到kafka的消息都需要指定Topic。Producer即消息生产者,向Broker发送......
  • UI界面+treeviwe+dataGridView
    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Runtime.Interop......
  • 10.常用的lambda表达式
    1.list转map工作中,我们经常遇到list转map的案例。Collectors.toMap就可以把一个list数组转成一个Map。代码如下:1publicclassTestLambda{23publicstati......
  • 【分布式技术专题】「架构实践于案例分析」总结和盘点目前常用分布式事务特别及问题分
    分布式事务分布式事务的场景什么场景下会出现分布式事务?TX协议⼀种分布式事务协议,包含⼆阶段提交(2PC),三阶段提交(3PC)两种实现。二阶段提交方案:强一致性事务的发起者称协调者,事......
  • winform日历控件
     分享一个漂亮的winform自定义控件,做考勤、日程管理、计划最好的自定义控件了,能够添加备注等等。......
  • 嵌入式开发常用技巧及编程知识
    嵌入式开发常用技巧及C/C++知识​​引言​​​​查询程序占据的内存大​​​​static静态变量​​​​‘##’连接符​​​​断言函数​​​​宏定义与条件变量​​​​#if.......