Sorting problem in Vb project for Numeric Data

In my vb projet i have used combobox control and set its Style property to '2-DropDown' and sorted property as "True".

At the time of form load event i have filled this combo box with numeric fields. But in combo box drop down listing ,it treat that fields as string.

Current Output
E-G.       Database Table         In Combo-box Listing
             (record Set)
                   1                              1
                   2                              1
                   3                              10
                   7                              11
                   1                              2
                   9                              22
                   10                            3
                   22                            9


Expected Output Should be as follows:
E-G.       Database Table         In Combo-box Listing
             (record Set)
                   1                              1
                   2                              1
                   3                              2
                   7                              3
                   1                              7
                   9                              9
                   10                            10
                   22                            22

Thanks in Advance

LVL 6
badalpatelAsked:
Who is Participating?
 
tang_tzuchiCommented:
You just change your sql statement to sort int he order you want before populate to the drop down menu....
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
... and change the "sorted" property to false on the combo box.

Indeed, combobox treats as strings.
hence, you could also left-pad the numerical value with spaces (best combined by applying a fixed-width font to the combobox)


0
 
badalpatelAuthor Commented:
My database is 'Access'. Actually I don't want to change the properties which i have set and i would like to sort the numbers in combobox in ascending order. They are populating in ascending order but same as string ordering instead of numerical order. Please...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
sivachirravuriTeam Lead Commented:
To sort the records accoringly use the following query & fetch the record. This is one of the solutions that will be very useful.

select * from test order by cint(srno) asc

Sample VB code:

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Form_Load()
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\VENEV6\Desktop\TEST.MDB;Persist Security Info=False"
rs.Open "select * from test order by cint(srno) asc", cn, adOpenDynamic, adLockOptimistic

While Not rs.EOF
    Combo1.AddItem rs(0)
    rs.MoveNext
Wend
End Sub


0
 
mploschiavoCommented:
its sorting on ascii versus integer or decimal?..

why dont you changed the the datatype of the of the dataset.
0
 
badalpatelAuthor Commented:
hi sivachirravuri

i have used combobox control and set its Style property to '2-DropDown' and sorted property as "True".
i cant change this property due to my other requirement
0
 
sivachirravuriTeam Lead Commented:
Hi Badalpatel,
you can use this code when combobox control's Style property is set to '2-DropDown'. But you need to make sored false. BCoz this code anywaz will do that.


0
 
sandip132Commented:
In this example this is done for Listview, Please refer the code.

http://www.codeguru.com/vb/controls/vb_listview/article.php/c1669/
0
 
badalpatelAuthor Commented:
i didnt get my answer of my question..
anyway u can split it they all tried but there answer was not right
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>they all tried but there answer was not right
Well, I am sure that if you tried my suggestion with left-padding the numerical data with spaces it will work (I used that alot already)...

also, you never came back with the answer to if the field is numerical data type or not, I guess that table field is actually defined as text but contains numerical data, which is not the same as a numerical data type
0
 
Christopher KileCommented:
>i didnt get my answer of my question..
You did get answers, they just didn't tell you what you wanted to hear.

>anyway u can split it they all tried but there answer was not right

You can't change the comparison function for a drop-down list.  It ALWAYS sorts as text if Sorted = True.   No amount of expertise can change that.  If the drop-down list allowed you to define your own comparision function, then you would be able to sort by whatever you want.  Because it doesn't, you have to live with the sort order that it allows and format your data so it will sort in the order in which you would like to see it, or you have to sort it yourself before adding the list items in sorted order.  lBoth of these solutions have been offered to you, but you continue to ask for the impossible.  sandip132 comes the closest to what you want because the solution (s)he offers would appear to the user to be doing exactly what you've requested, but his solution requires you to use the Common Controls ListView with some significant C++ wrapper code.

You never explained your "other requirements" that forced you to set this box to Sorted = True.  That requirement is faulty and should be revisited; it is a techinical specification, not functional, and as such should be modified if the function you require (a list of options sorted according to your requirement) is to be implemented.

I recommend that Venabili's suggested split of points be made.

I suggest that Venabili's point distribution be accepted as the querent has rejected all correct solutions for this question.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.