Databinding in multiple ComboBoxes

Posted on 2005-03-18
Medium Priority
Last Modified: 2008-03-06
I am developing a windows application for booking courses.  On the main input form the user inputs applicant name etc.  He/she then has to select the course.  The course selection is in two parts via two comboboxes.  The first combobox is the course ID from a 'Course Template' table in the dataset.  the second is the dates related to each course from a 'Courses' table in the dataset.  Each of these comboboxes are also connected to the main course booking record using databinding - this is so that, when the booking record is selected, it displays the correct course and date.
I can get the Course Template combobox populated.  The problem I have is with the Courses (i.e. the Dates) combobox.  I can not work out how to program it so that it only shows the relevant dates for the particular course - and to change the listing on reselection of the Course Template combobox.
I have tested this using a datagrid using data relations but can not see how to do the same thing with a combobox.
Can anyone advise please (code snippet would be helpful)
Question by:iantale
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
LVL 25

Accepted Solution

RonaldBiemans earned 1000 total points
ID: 13572797
Hi iantale, Something like this

    Dim ds As New DataSet
    Dim dvChild As DataView

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SqlDataAdapter2.Fill(ds, "parent")
        SqlDataAdapter1.Fill(ds, "child")

        Dim dr As New DataRelation("parent_child", ds.Tables("parent").Columns("id"), ds.Tables("child").Columns("id"))

        dvChild = ds.Tables("child").DefaultView
        ComboBox1.DataSource = ds.Tables("parent")
        ComboBox1.ValueMember = "id"
        ComboBox1.DisplayMember = "mytext"

        ComboBox2.DataSource = dvChild
        ComboBox2.DisplayMember = "MyText2"

        AddHandler ComboBox1.SelectedIndexChanged, AddressOf TEST

    End Sub

    Private Sub TEST(ByVal sender As System.Object, ByVal e As System.EventArgs)
        dvChild.RowFilter = "ID = " & ComboBox1.SelectedValue
    End Sub

Author Comment

ID: 13581334
A nice clear answer to a problem that had me confused.
Thanks very much.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression
Suggested Courses

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