473,395 Members | 1,541 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,395 software developers and data experts.

restricting combobox items

TS
This is getting very frustrating. I placed the same question before twice and
got no response. Hopefully I'll get one this time.
What I want to do is to restrict the items in one of the cbo boxes in my
windows form based on what is selected in another cbo box.
Example: When I choose "George" from the cbo box that shows the clients last
names, I want when I click on the cbo box that shows the first names to see
only the first names who have "George" as their last name.

What is the syntax for that?????

The code I used to open a connection to the SQL database where the data in
the two cbo boxes is generated from is as follows:-

Private Sub ConnectSQL_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ConnectSQL.Click
Dim SQLEV As SqlClient.SqlConnection = New SqlClient.SqlConnection()
Dim cmd As SqlClient.SqlCommand
Dim ClientName As SqlClient.SqlDataReader

SQLEV.ConnectionString = "Persist Security Info=true;Integrated
Security=false;User ID=sa;Password=xxxx;database=yyyy;server=zzzz"
SQLEV.Open()
cmd = New SqlClient.SqlCommand("SELECT * FROM qmf_cint", SQLEV)

ClientName = cmd.ExecuteReader
cbo_ChildLName.Items.Clear()
cbo_ChildFName.Items.Clear()
Do While ClientName.Read

cbo_ChildLName.Items.Add(Trim(ClientName.Item("Las t_Name").ToString))

cbo_ChildFName.Items.Add(Trim(ClientName.Item("Fir st_Name").ToString))
Loop
SQLEV.Close()

End Sub


--
TS
Nov 21 '05 #1
5 1523
Hi TS,

One of several possible methods is to use a dataview as the datasource
for the FirstName combo box. Then in the LastName combo box Selected
Value or Index Changed event use the dataview's RowFilter to filter the
items in the Firstname combobox.

Michelle

Nov 21 '05 #2
TS
Thanks for your reply. Do I still have to create a dataview? I already went
through all kind of pains to let my form connects to the SQL database. Why do
I have to create a dataview if the cbo boxes are generated from the SQL
database? I don't want to create a dataset... Any ideas??

"Michelle" wrote:
Hi TS,

One of several possible methods is to use a dataview as the datasource
for the FirstName combo box. Then in the LastName combo box Selected
Value or Index Changed event use the dataview's RowFilter to filter the
items in the Firstname combobox.

Michelle

Nov 21 '05 #3
Hello,

The results of a dataview can be filtered with one simple statement so
it's a convenient tool to use. Other possible methods could be:

1) create a second query that will get the firstnames when the
lastname is selected (use LastName as a parameter)
2) when you are looping through your ClientName datareader load all of
the names from the query into a collection then filter the results of
the collection when the last name is selected:

for each name in mycollection
if mycollection.LastName = cboLastName.text then
cboFirstname.items.add(mycollection.Firstname)
end if
next
Personally, I'd use a dataview but any of these methods will work.

Thanks,
Michelle

Nov 21 '05 #4
TS
Thank you so much again for being patient with me. Excuse my ignorance, I'm
relatively new to the .net world.
To create a dataview do I need to create first a dataset using ADO.net? Can
you please help me with the code to create the dataview.

"Michelle" wrote:
Hello,

The results of a dataview can be filtered with one simple statement so
it's a convenient tool to use. Other possible methods could be:

1) create a second query that will get the firstnames when the
lastname is selected (use LastName as a parameter)
2) when you are looping through your ClientName datareader load all of
the names from the query into a collection then filter the results of
the collection when the last name is selected:

for each name in mycollection
if mycollection.LastName = cboLastName.text then
cboFirstname.items.add(mycollection.Firstname)
end if
next
Personally, I'd use a dataview but any of these methods will work.

Thanks,
Michelle

Nov 21 '05 #5
No problem,

Yes, I believe you do need a dataset. Here's an example of how to fill
the dataview:

myDataView.Table = myDataset.Tables(0)

Thanks,
Michelle

Nov 21 '05 #6

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

Similar topics

3
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the...
1
by: Rachel Suddeth | last post by:
When I put a ComboBox on a form, I can enter strings through the designer to fill Items collections. I have put a ComboBox in a UserControl, and exposed the the Items collections with the same...
0
by: tupolev | last post by:
Hi, I already post this item but now I know whats wrong: I want to allow the user to edit the items in a combobox. The problem is that the textchange event works just one time (for the first...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
8
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the...
7
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to create a customized ComboBox where the methods ComboBox.Items.Add and ComboBox.Items.Insert will behave thusly: -- If the item is not present, add it. -- If the item is present, set the...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
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...

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.