简体   繁体   中英

Datagridview Refresh window c# desktop application

I have three forms:

  1. Form1 (Which is Mdi)
  2. Form2 (child of mdi)
  3. Form3 (child of Form2)

In my application Form1(MDI) open first,in which its child form (Form2) has open through menu, now Form2 has linkButton on which when I click a another form (Form3) has open. Form3 has DataGridView1 which is bounded on formLoad of Form3.

What i want that after binding of DataGridView1 its 2nd row should come as selected. For that I am writing this code:

DataGridView1.Rows[1].Selected = true; // 1 is the index of that row.

But this code is not working and the problem is that DataGridView is not getting refreshed.

你可以试试这个

DataGridView1.CurrentCell = DataGridView1[0, 1]

Not really sure if I still get the problem, is the problem that you do the row selection on Form.Load event and it doesn't work? Try to use your code in Form.Activated event.

You have to bind datasource occasionally

DataGridView1.DataSource = YOUR_DATA_SOURCE;

then

DataGridView1.Rows[0].Selected = true;
DataGridView1.CurrentCell = DataGridView1.Rows[1].Cells[0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM