By default the selected index of the combobox should be the first item.
If cboAtt.Items.Count = 0 Then For i = 0 To nums(att) cboAtt.Items.Add(cat(att)(i)) Next cboAtt.SelectedIndex = 0 ElseIf cboAtt.Items.Count > 0 Then cboAtt.Items.Clear() For i = 0 To num(att) cboAtt.Items.Add(cat(att)(i)) Next Else Return End If
Now, when the users selects another value from the combobox, I want that value to be swapped with the initial value of the array (if order is 1,2,3 and user selects 3 then order becomes 3,1,2),
which I do with the following function:
Function swap(ByVal orig As String, ByVal swapB As String) As String Dim init, swapd, tmp As String init = orig swapd = swapB tmp = init init = swapd swapd = tmp Return init End Function
The function is used here:
Private Sub cboAtt_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboAtt.SelectedIndexChanged swap1 = swap(cat(att)(cboAtt.SelectedIndex), cat(att)(0)) swap2 = swap(cat(att)(0), cat(att)(cboAtt.SelectedIndex)) cat(att)(cboAtt.SelectedIndex) = swap1 cat(att)(0) = swap2 cboAtt.Items.Clear() For i = 0 To num(att) cboAtt.Items.Add(cat(att)(i)) Next End Sub
This works perfectly, but now I want the combobox to display the new (initial) value that is swapped, except than when I do that the cboAtt_SelectedIndexChanged event is triggered which results to an infinite loop --> crash. Anyone knows how to avoid this?
Best regards
This post has been edited by trashr0x: 06 November 2009 - 01:43 AM

New Topic/Question
Reply




MultiQuote




|