Combo Box And Sort Ascending

Gary Simpson 471 Reputation points
2023-04-24T14:22:31.5866667+00:00

Hi Good People. I have a Combo Box on my Form that will not Sort Ascending or Descending, I load the Comb Box with Week Numbers From my SQL Database when the Form Loads. But when I click on the Combo Box (Dropped Down) The Numbers Are Not sorted Code And Picture Below. Can You Help Kind Regards Gary

 Private Sub LoadCmbxWeekNumber()

        SQL.ExecQuery("SELECT * FROM MultiRecords")

        If SQL.RecordCount < 1 Then Exit Sub

        If SQL.RecordCount > 0 Then

            'Dim WN As Double = GetDouble(TxtWeekNumber.Text)
            If String.IsNullOrEmpty(TxtDriverName.Text) Then

                SQL.ExecQuery("SELECT DISTINCT WeekNumber FROM MultiRecords ORDER BY WeekNumber ASC")

                For Each r As DataRow In SQL.SQLDT.Rows
                    CmbxWeekNumber.Items.Add(r("WeekNumber").ToString)
                Next

            ElseIf Not String.IsNullOrEmpty(TxtDriverName.Text) Then
                SQL.AddParam("@DriverName", TxtDriverName.Text)
                SQL.ExecQuery("SELECT WeekNumber WHERE DriverName=@DriverName ORDER BY WeekNumber ASC")
                For Each r As DataRow In SQL.SQLDT.Rows
                    CmbxWeekNumber.Items.Add(r("CmbxWeekNumber").ToString)
                Next

            End If
        End If

    End Sub

Week Number Problem

Developer technologies | VB
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2023-04-24T14:43:26.9433333+00:00

    If possible, change the type of the WeekNumber column to int or another integer type. If this is not yet possible, then use ORDER BY Cast(WeekNumber AS int).

    And do not set the Sorted property of the combobox.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.