6 Replies Latest reply on Mar 29, 2013 10:35 AM by Chris Chu

    remove items from combo box

    Chris Chu

      This is a simple code but I coudlnt' figure out how to removeitem from the combo box. Any help, please

      I want to add from letter "A" to "Y" to the cboRev.  except "I" "O" "Q" "S" and "X"

      Thx

       

       

           istart = 65 ' Start with letter "A"

          iEnd = 89   ' End with letter "Y"

          iSkip(0) = 73 'Letter "I"

          iSkip(1) = 79 'Letter "O"

          iSkip(2) = 81 'Letter "Q"

          iSkip(3) = 83 'Letter "S"

          iSkip(4) = 88 'Letter "X"

                    iListIndex = 0

                    For i = istart To iEnd

                      cboRev.AddItem Chr(i) 'Add letter "A" to "X" to the cboRev

                      iListIndex = iListIndex + 1

                      For j = 0 To 4

                          If i = iSkip(j) Then cboRev.RemoveItem (iListIndex - 1)

                      Next

                  Next

        • Re: remove items from combo box
          Manish Kumar

          Try this

           

          .....

          Dim istart As Integer

          Dim iEnd As Integer

          istart = 65 ' Start with letter "A"

          iEnd = 89   ' End with letter "Y"

           

          Dim collItemToSkip As New Collection

          Call collItemToSkip.Add(73, "k-" & 73) 'Letter "I"

          Call collItemToSkip.Add(79, "k-" & 79) 'Letter "O"

          Call collItemToSkip.Add(81, "k-" & 81) 'Letter "Q"

          Call collItemToSkip.Add(83, "k-" & 83) 'Letter "S"

          Call collItemToSkip.Add(88, "k-" & 88) 'Letter "X"

          On Error Resume Next

          iListIndex = 0

          For i = istart To iEnd

              Dim item As Integer

              item = collItemToSkip.item("k-" & i)

              If item = 0 Then

                  cboRev.AddItem Chr(i) 'Add letter "A" to "X" to the cboRev

                  iListIndex = iListIndex + 1

              End If

          Next

          .....

          • Re: remove items from combo box
            Simon Turner

            You could just avoid adding those items in the first place.

            The problem with your code by the way, is that you need to subtract 1 from iListIndex after removing the item from the list (otherwise it is too large).

            • Re: remove items from combo box
              Jacob Cordingley

              Sub fillcombo(ByVal excludelist As List(Of Char))
                      For ii As Integer = 65 To 90
                          If Not (excludelist.Contains(Convert.ToChar(ii))) Then
                              ComboBox1.Items.Add(Convert.ToChar(ii))
                          End If
                      Next
              End Sub

               

                Dim xChar As New List(Of Char)    

                xChar.Add("I")      

                xChar.Add("O")      

                xChar.Add("Q")  

                xChar.Add("S") 

                xChar.Add("X")  

                xChar.Add("Z")    

                fillcombo(xChar)