我有下面这段代码,点击它将进度列的默认值从0更改为1.现在的问题是单击数据网格时也会刷新。我希望它能够刷新,但我想保留它的位置并移到它下面的下一行。刷新后,光标会按预期返回到开始位置。是的,我知道这很明显是因为我在最后调用了refreshDataGrid函数,所以它会一直这样做。甚至在数据网格刷新时移动到下一行
private void button4_Click(object sender, EventArgs e)
{
string connectionString2 = "Data Source=LPMSW09000012JD\\SQLEXPRESS;Initial Catalog=Pharmacies;Integrated Security=True";
string query2 = "UPDATE dbo.[" + comboBox4.Text + "] SET Progress= '1' where code = '" + comboBox2.Text + "'; ";
using (SqlConnection connection = new SqlConnection(connectionString2))
{
SqlCommand command = new SqlCommand(query2, connection);
command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();
}
textBox1.Clear();
textBox3.Clear();
comboBox3.ResetText();
comboBox2.SelectedIndex = comboBox2.SelectedIndex + 1;
if (dataGridView3.CurrentRow != null)
dataGridView3.CurrentCell =
dataGridView3.Rows[Math.Min(dataGridView3.CurrentRow.Index + 1, dataGridView3.Rows.Count - 1)]
.Cells[dataGridView3.CurrentCell.ColumnIndex];
refreshDataGrid();}
我希望这个代码特定块可以解决这个问题:
if (dataGridView3.CurrentRow != null)
dataGridView3.CurrentCell =
dataGridView3.Rows[Math.Min(dataGridView3.CurrentRow.Index + 1, dataGridView3.Rows.Count - 1)]
.Cells[dataGridView3.CurrentCell.ColumnIndex];
什么,我试图做的是捕获突出显示的行索引的当前位置,并不管我打电话refreshDataGrid函数,它仍然会依次移动,而不是每次从头开始。 有没有办法做到这一点?再次解释一下,我想保留当前突出显示的行索引,并让它移动到下一行,而不必担心刷新时重新开始。例如。如果我从第1行开始,那么即使我调用refreshDataGrid函数,它也会转到第二行。
使用的UpdatePanel – mjb