dataInfo = new DeviceManage.设备运行(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Selected == true) { dataInfo.dev_no = sbbh.Text = dataGridView1.Rows[i].Cells[0].Value.ToString(); dataInfo.date = dateTimePicker1.Text = dataGridView1.Rows[i].Cells[1].Value.ToString(); dataInfo.starttime = dateTimePicker2.Text = dataGridView1.Rows[i].Cells[2].Value.ToString(); dataInfo.endtime = dateTimePicker3.Text = dataGridView1.Rows[i].Cells[3].Value.ToString(); dataInfo.endwhy = tjyy.Text = dataGridView1.Rows[i].Cells[4].Value.ToString(); dataInfo.devstatus = yxzt.Text = dataGridView1.Rows[i].Cells[5].Value.ToString(); dataInfo.remark = bz.Text = dataGridView1.Rows[i].Cells[6].Value.ToString(); } 同义改写
时间: 2024-01-24 14:05:24 浏览: 422
以下是对上述代码的同义改写:
```
DeviceManage.设备运行 dataInfo = new DeviceManage.设备运行();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Selected == true)
{
sbbh.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
dateTimePicker1.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
dateTimePicker2.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
dateTimePicker3.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
tjyy.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
yxzt.Text = dataGridView1.Rows[i].Cells[5].Value.ToString();
bz.Text = dataGridView1.Rows[i].Cells[6].Value.ToString();
dataInfo.dev_no = sbbh.Text;
dataInfo.date = dateTimePicker1.Text;
dataInfo.starttime = dateTimePicker2.Text;
dataInfo.endtime = dateTimePicker3.Text;
dataInfo.endwhy = tjyy.Text;
dataInfo.devstatus = yxzt.Text;
dataInfo.remark = bz.Text;
}
}
```
这个代码段的作用是将选中的行中的数据填充到表单上,并将该行数据保存在 `dataInfo` 对象中。同义改写后的代码与原代码的功能相同,只是稍微重构了一下。
阅读全文