Two points here - @michael_davies has given you the solution to
Quote:
I want to Show Last Record added in First row...
Here is his link as a clickable link
How to add new row at particular position in datagridview[
^]. Essentially, instead of inserting a new row at the bottom of the control, add it as row 0 each time. E.g If
drow
is your new row
dg1.Rows.InsertAt(drow, 0)
To address the sorting aspect of your question (which is no longer required, but I still think it is worth pointing this out) ...Your code
dg1.Sort(dg1.Rows(0), ListSortDirection.Descending)
is sorting on the first column of the DataGridView. If that column does not contain an index or the time the row was added then you will not get the order you want. You could add another column to your DGV and populate it each time with
dg1.Rows.Count + 1
. Then sort on that column. If you don't want it to be visible, then just set the
Visible
property of the column to
False