Link to home
Start Free TrialLog in
Avatar of tunhien
tunhien

asked on

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!?
Avatar of SystemExpert
SystemExpert
Flag of United States of America image

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
Avatar of tunhien
tunhien

ASKER

No!
All I want is on the winform not on the web! :d
ASKER CERTIFIED SOLUTION
Avatar of e1v
e1v

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tunhien

ASKER

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
Avatar of tunhien

ASKER

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.
Avatar of tunhien

ASKER

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!