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);
            }
        }
相关推荐
从孑开始2 分钟前
ManySpeech.MoonshineAsr 使用指南
人工智能·ai·c#·.net·私有化部署·语音识别·onnx·asr·moonshine
可触的未来,发芽的智生20 分钟前
新奇特:黑猫警长的纳米世界,忆阻器与神经网络的智慧
javascript·人工智能·python·神经网络·架构
YuanlongWang20 分钟前
C# 中,依赖注入(DI)的实现方式
c#
lly2024061 小时前
SQL ROUND() 函数详解
开发语言
大宝剑1701 小时前
python环境安装
开发语言·python
前端开发爱好者1 小时前
尤雨溪官宣:"新玩具" 比 Prettier 快 45 倍!
前端·javascript·vue.js
欧阳呀1 小时前
Vue+element ui导入组件封装——超级优雅版
前端·javascript·vue.js·elementui
lly2024061 小时前
CSS3 多媒体查询
开发语言
SmartSoftHelp开发辅助优化2 小时前
C# WinForm 编程高手:程序,进程,线程。程序,窗体,UI,后台。是如何协调工作的?深度解析>SmartSoftHelp魔法精灵工作室
microsoft·ui·c#