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);
            }
        }
相关推荐
huohaiyu25 分钟前
Hashtable,HashMap,ConcurrentHashMap之间的区别
java·开发语言·多线程·哈希
千叶寻-30 分钟前
正则表达式
前端·javascript·后端·架构·正则表达式·node.js
Predestination王瀞潞5 小时前
IO操作(Num22)
开发语言·c++
宋恩淇要努力6 小时前
C++继承
开发语言·c++
沿着路走到底7 小时前
python 基础
开发语言·python
記億揺晃着的那天8 小时前
Vue + Element UI 表格自适应高度如何做?
javascript·vue.js·ui
沐知全栈开发8 小时前
C# 委托(Delegate)
开发语言
mit6.8248 小时前
[C# starter-kit] 命令/查询职责分离CQRS | MediatR |
java·数据库·c#
GISer_Jing8 小时前
ByteDance——jy真题
前端·javascript·面试
真的想不出名儿8 小时前
Vue 中 props 传递数据的坑
前端·javascript·vue.js