Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Databinding in multiple ComboBoxes

Posted on 2005-03-18
2
Medium Priority
?
450 Views
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)
Thanks,
0
Comment
Question by:iantale
2 Comments
 
LVL 25

Accepted Solution

by:
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"))
        ds.Relations.Add(dr)

        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
0
 

Author Comment

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

Featured Post

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.

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

571 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