• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 989
  • Last Modified:

Select the final row when form load in datagridview (VS 05)!

I have a DataGridView and set the datasource of it equal to a datatable.

I wanna When It's load and show, the current cursor is set at the final record!
Please show me how to do that!?
0
tunhien
Asked:
tunhien
  • 4
  • 3
1 Solution
 
SystemExpertCommented:
Hi,

you can go like this

If Not Page.IsPostBack Then
      dtgMaster.SelectedIndex = 0
      BindMaster()
      BindDetails()
End If

or you can go on live link


http://www.dotnetjohn.com/articles.aspx?articleid=14

thanks
0
 
tunhienAuthor Commented:
No!
All I want is on the winform not on the web! :d
0
 
e1vCommented:
After the data has been loaded into your DataGridView you can do this:

yourDataGridView.CurrentCell = yourDataGridView[0, yourDataGridView.Rows.Count - 1];
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tunhienAuthor Commented:
But if I wanna It wil select the new row! not the final row! --> how can I do that?
0
 
e1vCommented:
If your dataGridView have "Enable Adding" (AllowUserToAddRows = true) then the line I posted will select the new row.
0
 
e1vCommented:
If your dataGridView does not "Enable Adding", then you have to insert a new  row in the datasource (your table) before you select the last row
0
 
tunhienAuthor Commented:
No!
I have to  "Enable Adding" (AllowUserToAddRows = true) but if don't use
            "yourDataGridView.CurrentCell = yourDataGridView[0, yourDataGridView.Rows.Count - 1];"
It will select the first row.

And when I use the code above --> it select the final record but not the final row (new record).
And I tried with opmit "-1" in the code above but the IDE throw error when It ran.
0
 
tunhienAuthor Commented:
Sorry! :d

I don't know why when I set dataset in the constructor of form class instead of form_load so that when it load, the frist row is select first not the new row!

:d You're right!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now