General discussion


Help with Datagrid and Stand-Alone Data

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
'Add New Record into the DataGrid
'AddNew Items into the UserQuota
rsQuota("Usage") = QuotaUsage
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"
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:

SQL = "Select * From 'Table_Name'"
rsQuota.Source = SQL & " Order By " & DataGridQuota.Columns(ColIndex).DataField
Set DataGridQuota.DataSource = rsQuota

Any help would be appreciated.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Sorting on character field

by Glen_McLeod In reply to Help with Datagrid and St ...

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.


Collapse -

Sorting on character field

by tsaurman In reply to Sorting on character fiel ...


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.


Related Discussions

Related Forums