方法一(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);
}
}