• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 994
  • 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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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