winfrom 获取dataGridView1选中行数据

方法一(dataGridView1.CurrentRow.Index):

cs 复制代码
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    int RowIndex = dataGridView1.CurrentRow.Index;
                    infrared_heat model = new infrared_heat();
                    model.UUID = Tools.ToString(this.dataGridView1.Rows[RowIndex].Cells[1].Value);
                    model.test_date = (DateTime)Tools.ToDateTime(this.dataGridView1.Rows[RowIndex].Cells[2].Value);
                    model.station_name = Tools.ToString(this.dataGridView1.Rows[RowIndex].Cells[3].Value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

方法二(e.RowIndex 要找对事件):

cs 复制代码
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    infrared_heat model = new infrared_heat();
                    model.UUID = Tools.ToString(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value);
                    model.test_date = (DateTime)Tools.ToDateTime(this.dataGridView1.Rows[e.RowIndex].Cells[2].Value);
                    model.station_name = Tools.ToString(this.dataGridView1.Rows[e.RowIndex].Cells[3].Value);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
相关推荐
好运的阿财4 分钟前
OpenClaw工具拆解之host_workspace_write+host_workspace_edit
前端·javascript·人工智能·机器学习·ai编程·openclaw·openclaw工具
天若有情67317 分钟前
逆向玩家狂喜!用C++野生写法一键破解线性加密(不规范但巨好用)
开发语言·c++·算法
XiYang-DING18 分钟前
JavaScript
开发语言·javascript·ecmascript
skywalk816323 分钟前
代码高尔夫(Code Golf)是一种以“用最少的字符数实现特定功能”为核心目标的编程挑战或风格。
开发语言
xyq202427 分钟前
MySQL 安装配置
开发语言
鸽子一号32 分钟前
c#Modbus通信
开发语言·c#
念何架构之路1 小时前
Go Socket编程
开发语言·后端·golang
feifeigo1231 小时前
基于无迹变换的电网概率潮流分析 MATLAB 实现
开发语言·算法·matlab
时空系1 小时前
第13篇:综合实战——制作我的小游戏 Rust中文编程
开发语言·后端·rust
CoderCodingNo1 小时前
【信奥业余科普】C++ 的奇妙之旅 | 19:内存的门牌号——地址与指针的设计原理
开发语言·c++