Tarun Tak
Tarun Tak

Reputation: 411

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.

Upvotes: 1

Views: 857

Answers (3)

Vishal Suthar
Vishal Suthar

Reputation: 17194

You have to bind datasource occasionally

DataGridView1.DataSource = YOUR_DATA_SOURCE;

then

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

Upvotes: 0

jjokela
jjokela

Reputation: 337

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.

Upvotes: 0

Memet Olsen
Memet Olsen

Reputation: 4608

You can try this

DataGridView1.CurrentCell = DataGridView1[0, 1]

Upvotes: 1

Related Questions