Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:


Hi guys

I have a crystal report with 3 parameters company,city,lastname

I made a form with 3 ComboBoxes
cbCompany take values from company
cbCity from city and ComboBox3 from lastname

This is how I fill the ComboBoxes

VB
Private Sub fill_city()
        cn = New SqlConnection(strCon)
        cn.Open()
        cm = New SqlCommand("Select distinct City From Staff", cn)
        dr = cm.ExecuteReader
        While dr.Read
            cbCity.Items.Add(dr("City").ToString)
        End While
        cn.Close()
    End Sub

    Private Sub fill_company()
        cn = New SqlConnection(strCon)
        cn.Open()
        cm = New SqlCommand("Select distinct Company From Staff", cn)
        dr = cm.ExecuteReader
        While dr.Read
            cbCompany.Items.Add(dr("Company").ToString)
        End While
        cn.Close()
    End Sub


The problem is that I want when I choose a value from cbCompany
the cbCity to take values only for this company


Thanks in advance
Posted
Updated 19-Jan-13 1:46am
v2

1 solution

I am doubt your question is regarding Crystal Report or the form combo box logic?
your combo box should work as cascade combobox.

first fill the item to the company combo box cbCompany. then load the city combo when the user select a company. you can load the city combo with cbCompany SelectedIndexChanged event.

you have to modify the City combo stored procedure as

C#
string selectedCompany= cbCompany.SelectedValue;
cm = New SqlCommand("Select distinct City From Staff Where Company='" + selectedCompany + "'", cn)


I'm not much familer with VB.net coding. may be syntax are not correct.
 
Share this answer
 
Comments
jomachi 19-Jan-13 8:13am    
Probably the syntax is wrong because now the cbCity don't show any values
Tharaka MTR 19-Jan-13 8:21am    
yep, that because I'm not much familiar with VB.NET. but I think you have an idea what I'm explaining here. so, I hope you can resolve this.

please add a debug point to string selectedCompany= cbCompany.SelectedValue; place. and check wheter selected value is correctly pass to the sql or not.
jomachi 19-Jan-13 8:23am    
Anyway thank you my friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900