private void dataGridView1_CellContentClick
(object sender,DataGridViewCellEventArgs e)
{
int i,j;
i = dataGridView1.CurrentCell.RowIndex;
j = dataGridView1.CurrentCell.ColumnIndex;
txtcellvalue.Text = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
private void Setvaluebutton_Click(object sender, EventArgs e)
{
int i = 0;
//foreach(DataGridViewRow datagridviewrow in dataGridView1.Rows)
//{
i = dataGridView1.SelectedCells[0].RowIndex;
string study = dataGridView1.Rows[i].Cells[2].Value.ToString();
txtcellvalue.Text = dataGridView1.Rows[i].Cells[3].Value.ToString();
txtcellvalue1.Text = dataGridView1.Rows[i].Cells[4].Value.ToString();
string unit = dataGridView1.Rows[i].Cells[5].Value.ToString();
i = i + 1;
DialogResult dr = MessageBox.Show
("Would like to update the click yes!!",
"values", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
db.OpenDB();
string query = "Update [table] set [status]=" + study + ",
[limit]='" + txtcellvalue.Text + "' ,[limit2]='" + txtcellvalue1.Text
+ "',[unit]='" + unit + "' where [tno]=" + i + ";";
db.Update(query);
DatagridviewMethod();
db.CloseDB();
}
else
{
DatagridviewMethod();
}
// }
}
在这里,我试图在datagridview中显示所有数据库表值。在datagridview中显示所有值后,尝试替换datagridview中的单元格值,我可以编辑和替换另一个值,但在更新时它只会更新一行值而不是所有其他行(所有选定的行)在 datagridview 中一次的值。请给我任何建议吗?