Solved

search with combobox

Posted on 2008-10-03
8
285 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now