Solved

search with combobox

Posted on 2008-10-03
8
290 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
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.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

624 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