Question

i use this code to add a numbers to combobox

 for (int i = 15; i < 250; i++)
 {
   cbSumFrom.Items.Add(i);
 }

the problem is that i get something like

100

101

......

but i want like

15

16

17

......

how to fix it ?

Was it helpful?

Solution

Take a look at your ComboBox.Sorted property. If it is True then you get your unwanted behavior (default, string-based sort.) Since you are populating the combo box from what looks like a presorted list, make sure that ComboBox.Sorted is set to False.

OTHER TIPS

The problem is is that it appears the combo box is sorting the item and it's doing an ASCII comparison on each character to do it, so 100 comes before 15 because 10 is before 15. Take the sorting off the combo box and it should list them in the order you;ve added them

Try this...didn't tested it but try this...

 cbSumFrom.Items.Clear();
 for (int i = 15; i < 250;)
     {
       cbSumFrom.Items.Add(Convert.toString(i));

     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top