General discussion

  • Creator
    Topic
  • #2311220

    Help with Datagrid and Stand-Alone Data

    Locked

    by tsaurman ·

    I have a question/problem. I am using a Datagrid in VB and populating the grid with on-the-fly Stand-Alone data. When I use a ‘recordset.sort’ this grid sort fine except that the sorting is done on the first character. So all of the 1’s get sorted together with all of the 10’s and 100’….

    Her is the VB Code that I am using:
    Dim rsQuota As New ADODB.Recordset
    rsQuota.Fields.Append “Usage”, adChar, 25, adFldIsNullable
    rsQuota.Open
    ‘Add New Record into the DataGrid
    rsQuota.AddNew
    ‘AddNew Items into the UserQuota
    rsQuota(“Usage”) = QuotaUsage
    rsQuota.Update
    Set DataGridQuota.DataSource = rsQuota

    Private Sub DataGridQuota_HeadClick(ByVal ColIndex As Integer)
    ‘ Sort on the clicked column
    If rsQuota.Sort <> DataGridQuota.Columns(ColIndex).DataField & ” ASC” Then
    rsQuota.Sort = DataGridQuota.Columns(ColIndex).DataField & ” ASC”
    Else
    rsQuota.Sort = DataGridQuota.Columns(ColIndex).DataField & ” DESC”
    End If
    End Sub

    I would like to use the code listed below, but since I am not connecting to a Database I am have problems formatting the Select statement:
    [I am not sure what to use for the ‘From Table_Name’ since I am not connecting to a table.]

    Dim SQL
    SQL = “Select * From ‘Table_Name'”
    rsQuota.Close
    rsQuota.Source = SQL & ” Order By ” & DataGridQuota.Columns(ColIndex).DataField
    rsQuota.Open
    Set DataGridQuota.DataSource = rsQuota

    Any help would be appreciated.

    Thomas

All Comments

  • Author
    Replies
    • #3470122

      Sorting on character field

      by glen_mcleod ·

      In reply to Help with Datagrid and Stand-Alone Data

      The field you create in your recordset is a char type, and chars are sorted according to the first ‘letter’ in the field, regardless of whether it’s a digit or not. Therefore all 1’s will sort before all 2’s, etc., so 10 comes before 2.

      Change the field to a numeric type and it will sort correctly.

      Glen

      • #3470516

        Sorting on character field

        by tsaurman ·

        In reply to Sorting on character field

        Glen,

        Thank you, I had already fixed my problem. I just need another set of eyes looking at the code.

        I changed the code to this:
        rsQuota.Fields.Append “Usage”, adInteger, 25, adFldIsNullable

        Thank you.

        Thomas

Viewing 0 reply threads