By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

restricting combobox items

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.