473,651 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Distill Duplicate Elements in Drop Down in vb.net

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---------------

Nov 21 '05 #1
4 2831
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---------------
Nov 21 '05 #2
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---------------

Nov 21 '05 #3
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---------------

Nov 21 '05 #4
Gurvar,

When you are using a datasoure

http://groups.google.com/groups?selm...TNGP15.phx.gbl

I had this link still in my clipboard, because I showed it to Rodchar before
you

Cor
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1592
by: Kjell Breimo | last post by:
Hi, I have made a selectbox (<Select....><option...>...) with size=1(It has to be size=1). It contains about 40 elements. It is placed on the top of my webpage abd I would like to see as many elements as possible when it is opened. As default there is only 12 elements that shows and then I have to scroll down to the other 28 elements. Is there a way to set the selectbox to show more than 12 elements when its opened?
1
14025
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every entry you cannot choose the same value twice. For example, I cannot choose for entry 1 the same value in both selection boxes (gqCategory1Entry1 and gqCategory2Entry1)
2
1297
by: soup_or_power | last post by:
Can someone please explain why the following code breaks when there is a single drop-down list, otherwise works fine with multiple drop-down lists? Many thanks function xyz() { var f=document.forms; for(var i=0; i < f.elements.length; i++)
8
8979
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day, although it varies over time. The daemon that gets the error exits and restarts a few seconds later. Usually it's fine then, but sometimes the error happens three or more times in a row. Occasionally, instead, we get "ERROR: Cannot insert a...
0
2080
by: Donius | last post by:
Hello team. I'm running mysql 4.0.20-standard and i'm trying to do a query like this: INSERT IGNORE INTO `DonorPledges` ( nDonor_id, nPledgeYear, nTotalPaid, nTotalPledge ) SELECT
12
2127
by: capdownlondon | last post by:
Working in Access 2003. I have managed to duplicate a record using a button on a form with code: Private Sub Command16_Click() On Error GoTo Err_Command16_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
4
2559
by: sialater | last post by:
Hello, I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have members. I have this formatted in a way where the groups are in a drop down box. Once a group is selected, the two selection boxes below are refreshed with those who are members or non members of the selected group. The user has the ability to...
3
1709
by: MitchellEr | last post by:
Hi, I am in the process of creating several forms where a group of elements on the form need to be created dynamically. For example, in the case of one of the forms, I have a drop down for school, a text box for degree, and a text box for concentration. The form shows 3 of these groupings by default but would like the user to be able to "add more" 3 element groupings if need be and "remove" the additional elements if needed. The schools...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7299
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.