?
Solved

search with combobox

Posted on 2008-10-03
8
Medium Priority
?
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

718 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