Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I wish to display at the last row of datagridview. For that I used in Form_Load().
Is it correct or I have to use it in different event?

C#
Form_Load() 
{
    myDataGrid1.FirstDisplayedScrollingRowIndex=250;
    myDataGrid1.Rows[250].Selected = true;
    myDataGrid1.Rows[250].Cells[0].Selected = true;
}
Note: I found a solution before few years, but I forget the point

Thanks for the directions
Posted

Hi
you can use these codes after you r assigning datasource to the datagridview...

u can paste those codes next to
C#
myDataGrid1.DataSource = dt // some data source...



it will work fine... tested....

example code ::


C#
DataTable dt = new DataTable();
           dt.Columns.Add("column1", typeof(string));
           for (int i = 0; i < 15; i++)
               dt.Rows.Add("value " + i);

           dataGridView1.DataSource = dt;
           dataGridView1.FirstDisplayedScrollingRowIndex = 10;
           dataGridView1.Rows[10].Selected = true;
           dataGridView1.Rows[10].Cells[0].Selected = true;
 
Share this answer
 
Thanks..But It doesn't work, while you remove & add columns later...So changed the above lines to DataGridView1_GotFocus()..event, it works fine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900