Reputation: 411
I have three forms:
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
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
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
Reputation: 4608
You can try this
DataGridView1.CurrentCell = DataGridView1[0, 1]
Upvotes: 1