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!?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


you can go like this

If Not Page.IsPostBack Then
      dtgMaster.SelectedIndex = 0
End If

or you can go on live link

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

yourDataGridView.CurrentCell = yourDataGridView[0, yourDataGridView.Rows.Count - 1];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

tunhienAuthor Commented:
But if I wanna It wil select the new row! not the final row! --> how can I do that?
If your dataGridView have "Enable Adding" (AllowUserToAddRows = true) then the line I posted will select the new row.
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
tunhienAuthor Commented:
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.
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.