Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

search with combobox

Posted on 2008-10-03
8
Medium Priority
?
294 Views
Last Modified: 2010-04-23
Hi..
I have one table in the database, this table contains on two columns(BRANCH, TYPE),
the data are:
BRANCH      TYPE
=======      =====
BMW            320i
HONDA        ACCORD
HONDA        CITY
HONDA        CIVIC
TOYOTA      CAMRY

in visual studio 2005, there is one form have two comboboxes(cmbBRANCH, cmbTYPE),
both of them are connected to the database table,
cmbBRANCH is connected with BRANCH feild, and cmbTYPE connected with TYPE feild.

What I want is when the user choose the branch name thats being inside the first combobox(cmbBRANCH), the data related with this name will display in the second combobox (cmbTYPE),

for example: when the user choose HONDA from (cmbBRANCH),
all Types of HONDA (ACCORD, CITY,CIVIC) will display inside (cmbTYPE)

is there any solution for that?
0
Comment
Question by:Jassimi
  • 4
  • 4
8 Comments
 
LVL 8

Expert Comment

by:jtdebeer
ID: 22637675
You will have to setup 2 queries one for each combo box
Set ComboBox 1's DataFieldValue = where clause of the second combobox's query.

Query 1
"Select Branch from Table"
(Set autopostback on cmbBRANCH)


In the Databind Event of cmbBRANCH add the second bit of code....

Query2
"Select Type from Table where Branch = @cmbBranch.SelectedValue"
You might also want to set the DataValueField on cmbBranch
Set the initial cmbTYPE.Visible = False
and then update the cmbType.Visible = True on Postback databind event of cmbBranch


Hope this will help.
0
 
LVL 2

Author Comment

by:Jassimi
ID: 22637945
ok..
can you tell me where can I find sutopostback ?
0
 
LVL 8

Expert Comment

by:jtdebeer
ID: 22638044
It is a property you set on the control.
Either right click the combobox and select Properties check under Behaviour

or you can set programatically in the page load event
cmbBRANCH.AutoPostBack = True

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:jtdebeer
ID: 22638073
Dear Jassimi,
The suggestions I am passing is based on ASP.Net2 for web applications and not full blown VB Apps.
you will obviously not have page post backs in a desktop app.
Rather use an event to specify when the second control should bind with its dataset.
0
 
LVL 2

Author Comment

by:Jassimi
ID: 22638104
I tried it programatically and put    cmbBRANCH.AutoPostBack = True
but I got this error:
'AutoPostBack' is not a member of 'System.Windows.Forms.ComboBox'.
0
 
LVL 2

Author Comment

by:Jassimi
ID: 22638119
yea... I'm using windows application, not web application
0
 
LVL 8

Expert Comment

by:jtdebeer
ID: 22638364
You might want to try and populate the data to combobox2 on the combox1 event SelectedIndexChanged
0
 
LVL 2

Accepted Solution

by:
Jassimi earned 0 total points
ID: 22694703
Ok..
I got the solution,
first we have to but the following code in Load event,
 Dim dr As OleDbDataReader
Conn.Open()
        cmd.Connection = Conn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "SELECT distinct BRANCH  FROM table1"
        dr = cmd.ExecuteReader
        Do While dr.Read
                   cmbBRANCH.Items.Add(dr.Item("BRANCH"))
      Loop
        dr.Close()
        Conn.Close()

Second thing we have to put the following code in (cmbBRANCH) combobox:
Conn.Open()
   Dim SQLstr As String = "SELECT TYPE FROM table1 where BRANCH = " & cmbBRANCH.Text & ""
        Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
        DataAdapter1.Fill(DataSet1, "table1")
        Conn.Close()

          cmbTYPE.DataSource = DataSet1
           cmbTYPE.DisplayMember = "table1.TYPE"


with this method, when we choose the branch name from first combobox(cmbBRANCH), the data related with this name will display in the second combobox (cmbTYPE),
 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question