C# 4.0 表单。显示导致行选择松动的原因

C# 4.0 表单。显示导致行选择松动的原因,c#-4.0,datagridview,C# 4.0,Datagridview,我正在使用以下代码设置当前行 private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { gSelectedPlant = StaticClass.GlobalValue; dataGridView1.CurrentCell = dataGridView1.Rows[gSelectedPlant].Cells[0]; dat

我正在使用以下代码设置当前行

private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    gSelectedPlant = StaticClass.GlobalValue;

    dataGridView1.CurrentCell = dataGridView1.Rows[gSelectedPlant].Cells[0];
    dataGridView1.Rows[gSelectedPlant].Selected = true;
    gSelectedPlant = dataGridView1.CurrentCell.RowIndex;
}
在我的第二个表单中,它有一个后退按钮

private void btnCancel_Click(object sender, EventArgs e)
{
    int plantid = StaticClass.GlobalValue;
    //Properties.Settings.Default.PlantId = plantid;

    Program.fPlant = new frmPlant(plantid);
    Program.fPlant.Show();
    this.Hide();

 }

现在,第一种形式的数据绑定工作得很好。但是在Program.fPlant.Show()中,rowselection恢复为默认值(第一行),但我需要它维护选中的行

您显示的内容工作正常-问题在于您没有显示的某些代码,可能是构造函数或frmPlant或您的程序类中的代码-
Program.fPlant
是否是对类的静态引用?请展示你所有的代码。另外,你处理这个问题的方式,似乎有很多全局变量,可能是一个糟糕的设计。