views:

20

answers:

2

Here is my code.

for example TextBox1.Text= 12,34,45,67,67

            Dim process_string As String() = TextBox1.Text.Split(New Char() {","})
        Dim process As Integer

        For Each process In process_string 
            Combo1.Items.Add(process)
            count = count + 1
        Next process
      total_process.Text = count
    End If

    Dim array(count) As String
    Dim a As Integer
    For a = 0 To count - 1
        array(a) = Combo1.Items(a).ToString
    Next

    a = 0
    For a = count To 0
        Combo2.Items.Add(array(a).ToString)
    Next

i want to add values in reversed order in combobox2 that are available in combobox1 but when i run the application the second combobox remains empty and not showing any value.

+2  A: 

You've specified this for loop

 For a = count To 0

But you need to add STEP -1 to go backwards like that.

 For a = count To 0 Step -1
drventure
A: 

2 things. First of all, K.I.S.S. Keep it simple stupid

    For i As Integer = ComboBox1.Items.Count - 1 To 0 Step -1
        ComboBox2.Items.Add(ComboBox1.Items(i))
    Next

second: It didn't work because you forgot the Step -1 on your last loop

~~~~~~~~~~~~~~Edit~~~~~~~~~~~~~~

Sorting the data in a combo box should be done with the sorted property on a combo box

ComboBox3.Sorted = True

Sorting the data in reverse order should be done with arrays as you were trying to do before. The following code should suffice:

    Dim List As ArrayList = ArrayList.Adapter(ComboBox3.Items)

    List.Sort()
    List.Reverse()

    ComboBox4.Items.AddRange(List.ToArray)

If you wanted to get creative, you could potentially create your own combo box class and make your own version of the sorted property that allows for "sort alpha", "sort numeric", "sort alpha Desc", and "sort numeric desc" and perhaps some other options. But I'd only do that if you were going to use this in a lot of places.

Jrud
hhahahaha...i am stupid lol...thanks you
m.qayyum
Now how i can arrange items in ascending and descending order and add them to another two comboxes. i really can't handle these loops in vb.net
m.qayyum
lol KISS doesn't necessarily, mean the designer is stupid. Read the Wiki article: "There was no implicit meaning that an engineer was stupid; just the opposite." it means that you're intelligent, but you're over complicating the problem with extra variables and declarations. For ascending and descending order, I'll post some additional code.
Jrud
Ya i know ...i have read it...but i was really doing stupid loops though..lol
m.qayyum
Thanks for help...i have done ascending and descending also. So thanks again
m.qayyum