General discussion

Locked

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
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:


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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| 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.

Glen

Collapse -

Sorting on character field

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

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

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums