I have datagrid populated from Access database every 60 seconds in timer_tick() subroutine.
Dim direction As SortOrder
.
.
.
DataGridView1 ColumnHeaderMouseClick code :
direction = DataGridView1.SortOrder
MsgBox(direction.ToString())
Now, every other click it shows descending and other half ‘2’ , just number insted of Ascending.
Does anyone know why that is happening or how to fix it?
What I try to achieve is to retain sortorder after datagrid is automatically reloaded within timer tick() sub.
I found the answer:
http://www.tek-tips.com/viewthread.cfm?qid=1617798
Problem was that
DataGridView.SortOrder returns a value of Windows.Forms.SortOrder
(this variable type will retrieve current sort order)
whilst
DataGridView.Sort() is looking for a value of System.ComponentModel.ListSortDirection
(this variable type will set new sort order)
So we need something like:
Now the items in datagrid will remain ordered by the same column and ascending/descending after reload.