473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

duplicate in combobox.....

does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub

Nov 21 '05 #1
8 2229
Hi,

Try changing the For line to:

For i As Integer = 0 to (ComboBox1.Items.Count - 1)

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Supra" <su*****@rogers.com> wrote in message
news:PL********************@news01.bloor.is.net.ca ble.rogers.com...
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub

Nov 21 '05 #2
same problems.
Ken Dopierala Jr. wrote:
Hi,

Try changing the For line to:

For i As Integer = 0 to (ComboBox1.Items.Count - 1)

Good luck! Ken.


Nov 21 '05 #3
i solved it.....i found another newsgroup in windowform

it is item(i) instead of ComboBox1.SelectedItem

If ComboBox1.Items(i) = ComboBox1.Text Then

regards,

Supra wrote:
same problems.
Ken Dopierala Jr. wrote:
Hi,

Try changing the For line to:

For i As Integer = 0 to (ComboBox1.Items.Count - 1)

Good luck! Ken.


Nov 21 '05 #4
Supra,

That part you show is as well not right, however I will advice you to take
the answer from Ken as well. You solution should not work (when there is no
match) when you do not add that and you never take the first one. It is as
well not needed to convert the Text to String, while Text is already a
String. But that does not give errors.

And to confuse you even more, there is a much easier instruction for what
you are doing.
http://msdn.microsoft.com/library/de...exacttopic.asp

I hope this gives you an idea?

Cor

Cor
"Supra" <su*****@rogers.com>..
i solved it.....i found another newsgroup in windowform

it is item(i) instead of ComboBox1.SelectedItem

If ComboBox1.Items(i) = ComboBox1.Text Then
regards,

Supra wrote:
same problems.
Ken Dopierala Jr. wrote:
Hi,

Try changing the For line to:

For i As Integer = 0 to (ComboBox1.Items.Count - 1)

Good luck! Ken.

Nov 21 '05 #5
You are looping with "For i as Integer =1 to ...." but you don't use
it. You are checking SelectedItem (and you would want to check
SelectedItem.ToString rather than the object itself) where you should
check each item in the ComboBox whether it is selected or not - use
ComboBox1.items(i).ToString. Now maybe you are checking only the
selectedItem to see if it's text matches what you are inputing, but
what if the dup is somewhere else??

So fix both of those things and see which is needed...-

SelectedItem.ToString
and
ComboBox1.items(i).ToString

to see what fits with your logic....
On Fri, 24 Sep 2004 00:21:03 GMT, Supra <su*****@rogers.com> wrote:
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub


bceggersATcomcastDOTnet
Nov 21 '05 #6
In article <PL********************@news01.bloor.is.net.cable. rogers.com>, Supra wrote:
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.


Private Sub ComboBox1_KeyPress _
(ByVal sender As Object, ByVal e As KeyPressEventArgs) _
Handles ComboBox1.KeyPress

If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)

If ComboBox1.FindStringExact (ComboBox1.ComboBox1.Text) = -1 Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If

End Sub
FindString and FindStringExact are your friends...
--
Tom Shelton [MVP]
Nov 21 '05 #7
thank

Barry wrote:
You are looping with "For i as Integer =1 to ...." but you don't use
it. You are checking SelectedItem (and you would want to check
SelectedItem.ToString rather than the object itself) where you should
check each item in the ComboBox whether it is selected or not - use
ComboBox1.items(i).ToString. Now maybe you are checking only the
selectedItem to see if it's text matches what you are inputing, but
what if the dup is somewhere else??

So fix both of those things and see which is needed...-

SelectedItem.ToString
and
ComboBox1.items(i).ToString

to see what fits with your logic....
On Fri, 24 Sep 2004 00:21:03 GMT, Supra <su*****@rogers.com> wrote:
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub


bceggersATcomcastDOTnet


Nov 21 '05 #8
thank

Barry wrote:
You are looping with "For i as Integer =1 to ...." but you don't use
it. You are checking SelectedItem (and you would want to check
SelectedItem.ToString rather than the object itself) where you should
check each item in the ComboBox whether it is selected or not - use
ComboBox1.items(i).ToString. Now maybe you are checking only the
selectedItem to see if it's text matches what you are inputing, but
what if the dup is somewhere else??

So fix both of those things and see which is needed...-

SelectedItem.ToString
and
ComboBox1.items(i).ToString

to see what fits with your logic....
On Fri, 24 Sep 2004 00:21:03 GMT, Supra <su*****@rogers.com> wrote:
does ne 1 know how to prevent duplicated in combobox? i convert from
vb6 to vb.net. but in vb6 would work.

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
e.Handled = True
AxWebBrowser1.Navigate(ComboBox1.Text.ToString)
Dim bFound As Boolean
bFound = False
For i As Integer = 1 To ComboBox1.Items.Count
If ComboBox1.SelectedItem = ComboBox1.Text.ToString Then
bFound = True
Exit For
End If
Next
If bFound = False Then
ComboBox1.Items.Add(ComboBox1.Text.ToString)
End If
End If
End Sub


bceggersATcomcastDOTnet


Nov 21 '05 #9

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

Similar topics

7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
6
by: Lee-Anne Waters via AccessMonster.com | last post by:
Hello, just a small problem i'm hoping someone would help me with. i have a form which adds skills to a person but i want to make sure that the skill is not entered twice. is there anyway of...
8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
4
by: gurvar | last post by:
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...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
10
by: Backwards | last post by:
Hello all, I'll start by explaining what my app does so not to confuss you when i ask my question. ☺ I have a VB.Net 2.0 app that starts a process (process.start ...) and passes a prameter...
1
by: bruce24444 | last post by:
I am designing a database to use a work to assign files to certain people. Form includes Date textbox, File Number textbox, File Type combobox and Assigned To combobox. The form is working fine and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.