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);
            }
        }
相关推荐
dingdingfish1 小时前
Bash学习 - 第3章:Basic Shell Features,第5节:Shell Expansions
开发语言·学习·bash
rainbow68891 小时前
C++开源库dxflib解析DXF文件实战
开发语言·c++·开源
deepxuan1 小时前
Day7--python
开发语言·python
禹凕1 小时前
Python编程——进阶知识(多线程)
开发语言·爬虫·python
xkxnq1 小时前
第五阶段:Vue3核心深度深挖(第74天)(Vue3计算属性进阶)
前端·javascript·vue.js
三小河1 小时前
Agent Skill与Rules的区别——以Cursor为例
前端·javascript·后端
蜡笔小马1 小时前
10.Boost.Geometry R-tree 空间索引详解
开发语言·c++·算法·r-tree
IOsetting1 小时前
金山云主机添加开机路由
运维·服务器·开发语言·网络·php
Hilaku1 小时前
不要在简历上写精通 Vue3?来自面试官的真实劝退
前端·javascript·vue.js
唐梓航-求职中2 小时前
编程-技术-算法-leetcode-288. 单词的唯一缩写
算法·leetcode·c#