Solved

search with combobox

Posted on 2008-10-03
8
287 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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