Solved

Sorting problem in Vb project for Numeric Data

Posted on 2006-11-09
15
357 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:badalpatel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +4
15 Comments
 
LVL 3

Accepted Solution

by:
tang_tzuchi earned 125 total points
ID: 17912303
You just change your sql statement to sort int he order you want before populate to the drop down menu....
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17912332
... 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
 
LVL 6

Author Comment

by:badalpatel
ID: 17912393
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 5

Assisted Solution

by:sivachirravuri
sivachirravuri earned 125 total points
ID: 17912568
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
 
LVL 2

Expert Comment

by:mploschiavo
ID: 17917463
its sorting on ascii versus integer or decimal?..

why dont you changed the the datatype of the of the dataset.
0
 
LVL 6

Author Comment

by:badalpatel
ID: 17920028
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
 
LVL 5

Expert Comment

by:sivachirravuri
ID: 17927800
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
 
LVL 12

Assisted Solution

by:sandip132
sandip132 earned 125 total points
ID: 17936268
In this example this is done for Listview, Please refer the code.

http://www.codeguru.com/vb/controls/vb_listview/article.php/c1669/
0
 
LVL 6

Author Comment

by:badalpatel
ID: 18290217
i didnt get my answer of my question..
anyway u can split it they all tried but there answer was not right
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18290435
>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
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 18542673
>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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Part One of the two-part Q&A series with MalwareTech.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question