Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:10:09+00:00 2026-06-12T07:10:09+00:00

I have datagrid populated from Access database every 60 seconds in timer_tick() subroutine. Dim

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:10:11+00:00Added an answer on June 12, 2026 at 7:10 am

    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:

    columnXY = DataGridView1.SortedColumn
    *' if no column set for sort use third one *
            If columnXY Is Nothing Then
                columnXY = DataGridView1.Columns(2)
            End If
    
    Dim SetSortOrder As ListSortDirection
    Dim GridSortOrder As SortOrder
    GridSortOrder = DataGridView1.SortOrder
    
            If GridSortOrder = Windows.Forms.SortOrder.Ascending Then
                SetSortOrder = ListSortDirection.Ascending
            ElseIf GridSortOrder = Windows.Forms.SortOrder.Descending Then
                SetSortOrder = ListSortDirection.Descending
            ElseIf GridSortOrder = Windows.Forms.SortOrder.None Then
                SetSortOrder = ListSortDirection.Ascending
            Else : GridSortOrder = ListSortDirection.Ascending
                MsgBox("not good")
            End If
    
    DataGridView1.DataSource = datasetXY.Tables(0)
    DataGridView1.Sort(columnXY, SetSortOrder)
    

    Now the items in datagrid will remain ordered by the same column and ascending/descending after reload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF DataGrid which is populated from a database. There is a
I have some problem to access the Window's DataContext from within a DataGrid. The
I have a datagrid in a WPF populated from a csv file. This is
I have a datagrid which populated by some data from sqlserver.I have datetime filed
I have a WPF Datagrid populated with data from one SQL table using Entity
I have a flex datagrid with cart items populated from a service. Each row
I have a WPF DataGrid that will be populated from a data table having
I have a DataGrid with data populated from an XML binding. I want to
I have a string that is populated from an Xceed datagrid, as such: study
I have a WPF datagrid, bound to a list populated by linq-to-sql from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.