473,406 Members | 2,956 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,406 software developers and data experts.

Check for existing value in Combobox list


I have a textbox and a combobox on a toolstrip. The user enters either an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of the
value in the combobox prior to setting the value. The procedure is shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?
Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object, ByVale
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 9 '07 #1
2 7085
On 9 jul, 15:37, DesCF <d...@aol.comwrote:
I have a textbox and a combobox on a toolstrip. The user enters either an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of the
value in the combobox prior to setting the value. The procedure is shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?

Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub

--
Using Opera's revolutionary e-mail client:http://www.opera.com/mail/
Hi...
How about to use a LIKE query: "SELECT Id FROM Table1 WHERE Id LIKE '"
+ TextBox1.Text + "%'"

Jul 10 '07 #2
I had it mind that I didn't want to open a connection back to the server
just to check for the existence of a Customer ID when the combobox is
already populated by a valid list of Customer ID's which I could check
against. What has occurred to me is perhaps something I don't quite
understand because of my 'newness' to this, i.e. if I have a dataset with
a datatable in it that contains a list of customers how do I check against
the table in the dataset and not the table back on the server ?

Des
On Tue, 10 Jul 2007 23:39:28 +0100, diAb0Lo <ga********@gmail.comwrote:
On 9 jul, 15:37, DesCF <d...@aol.comwrote:
>I have a textbox and a combobox on a toolstrip. The user enters either
an
ID in the textbox or selects a name from the combobox. When the user
selects a name from the combobox the textbox is filled in automatically
by
setting its .Text property equal to the .SelectedValue of the combobox.
When the user enters an ID in the textbox the combobox's .SelectedValue
is
set to the .Text value in the ID textbox. All works fine but it is
possible to enter a value in the ID textbox that does not exist in the
combobox. So I have written a procedure to check for the existence of
the
value in the combobox prior to setting the value. The procedure is
shown
below. My question is: Is it possible to do this without iterating
through the values, i.e. is there a single line of code using something
like .Contains that enables me to do the same thing ?

Private Sub txtCustIDEnter_Leave(ByVal sender As System.Object,
ByVal e
As System.EventArgs) Handles txtCustIDEnter.Leave

Dim strCustID As String = Me.txtCustIDEnter.Text.Trim.ToUpper

If strCustID.Length <0 Then
For Each drv As DataRowView In
Me.cboCustNameSelect.ComboBox.Items
If drv.Row.Item(0).ToString.ToUpper = strCustID Then
Me.cboCustNameSelect.ComboBox.SelectedValue = strCustID
Exit For
End If
Next
End If

End Sub

--

Hi...
How about to use a LIKE query: "SELECT Id FROM Table1 WHERE Id LIKE '"
+ TextBox1.Text + "%'"


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 11 '07 #3

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

Similar topics

2
by: SAN CAZIANO | last post by:
check required in a select how can i control if a combobox (a select) is not null (index is -1) or if index is 0 if the first element is for example a null value or simply a description of the...
5
by: Andrew | last post by:
I've got two tables in my DB, a Client table and an Event table. There are many events for each client. The form I designed is based off of the Client table and the subform within it is sourced...
13
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
1
by: Niclas | last post by:
Hi, in ASP .Net, I can associate a value with and item in a dropdown list, for example when binding to a list of employees, I can store the employeeid as a value associated with each name in in...
7
by: grummanf6f | last post by:
Hello Gurus, this probably is real simple for you but for me it's a bummer. I have one table in which I have basic data collected of schools. I have another data that is detailed info on the...
1
by: exapplerep | last post by:
I have a table with a particular field storing the names of authors. When I enter a new record I'd like to have a list of the existing entries come up from which one may choose. It is also...
7
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I have two forms which I am using for Shipping Entry. Now First Form(ShippingAlerts) Is fillup by persons working in customer services.and the Second...
2
by: =?Utf-8?B?RHJEQkY=?= | last post by:
I understand that the Value put into a DataGridViewComboBoxCell has to be a member of the Items list or an exception is thrown. I also understand that you can override that exception by handling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.