Form.Show causing to loose Row selection

亡梦爱人 提交于 2019-12-25 05:14:17

问题


I am setting the current row using the following code

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;
}

In my second form which has a back button.

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();

 }

Now the databindind in the first form works well . but at Program.fPlant.Show(), rowselection reverts to the default(first row), but I need it maintain selected row

来源:https://stackoverflow.com/questions/10761154/form-show-causing-to-loose-row-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!