Hi,
For x As Integer = 1 To 20
ComboBox1.Items .Add(x.ToString )
Next
ComboBox1.Items .Add("1")
ComboBox1.Sorte d = True
For i As Integer = ComboBox1.Items .Count - 1 To 1 Step -1
If ComboBox1.Items .Item(i).Equals (ComboBox1.Item s.Item(i - 1)) Then
ComboBox1.Items .RemoveAt(i)
End If
Next
Ken
-------------------------
"gurvar" <gu****@discuss ions.microsoft. com> wrote in message
news:13******** *************** ***********@mic rosoft.com...
Hi,
I'm actually trying to compare the elements within a drop down list.
If say #18 & #19 are same I want to remove #19.
Question is how do I make the elemental comparision?
And then delete the ;ast repeating element(s).
In vb6 I would do:
If (Combo5.List(Nu mY) = Combo5.List(Num Y - 1)) Then
In vb.net how do I go about.?
Thanks,
"Ken Tucker [MVP]" wrote:
Hi,
This code will add 20 items to a combobox and remove the last 18.
When removing an item by number start at the end of the list and work
forward to prevent referencing an item that isnt there anymore.
For x As Integer = 1 To 20
ComboBox1.Items .Add(x.ToString )
Next
For i As Integer = ComboBox1.Items .Count - 1 To 2 Step -1
ComboBox1.Items .RemoveAt(i)
Next
Ken
-------------------------
"gurvar" <gu****@discuss ions.microsoft. com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
Hi I'm trying to remove duplicate elements from
a Drop Down List Fill in VB.net.
Following code worked well with vb6. But I'm getting index out of range if
I
try to translate it to vb.net code at line#4. Any possible clues will be
appreciated. Thanks.
'To distill the Combo Element
NumY = Combo5.ListCoun t + 1 ''''''''''''''' Line1
For NumX = 1 To Combo5.ListCoun t '''''''line2
NumY = NumY - 1 '''''''line3
If (Combo5.List(Nu mY) = Combo5.List(Num Y - 1)) Then
''''''line4
Combo5.RemoveIt em (NumY) '''''''''''''li ne5
End If '''''line6
Next ''''line7
---------------In vb.net---------------