?
Solved

Combobox with linked tables

Posted on 2014-01-08
5
Medium Priority
?
301 Views
Last Modified: 2014-01-15
Is it possible to have a combobox on a simple input form display the values from one table, but when the combobox is opened, has all of the available values from the 2nd table.

For example, a form with values from a UserTable and a link to Department table.

I want to display all of the values from the UserTable:
FirstName
LastName
Shift
Phone
Department

But I want Department to be a combobox that displays the appropriate Department for each record in the UserTable when navigating, but when opened, shows all of the Departments from the DepartmentTable.

Is this possible?

Thanks for any help.
0
Comment
Question by:PSCTECH
[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
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:5teveo
ID: 39766554
EEscreenshot20140107
shot in the dark - screen image guess...

Use a repeater and tie to a datasource to generate master grid and then embed a dropdownlist (also linked to datasource) inside repeater in column 4 of my example

I included HTML and code snipets for screen print...

</head>
 <body>

    <h3>Repeater Example</h3>

    <form id="form1" runat="server">

       <b>Repeater1:</b>
       <br />

       <asp:Repeater id="Repeater1" runat="server">

          <HeaderTemplate>
             <table border="1">
             <tr>
                <td>First</td>
                <td>Last</td>
                <td>Something</td>
                <td>Department</td>
             </tr>
          </HeaderTemplate>

          <ItemTemplate>
             <tr>
                <td> <%# Container.DataItem %> </td>
                <td> <%# Container.DataItem %> </td>
                <td> <%# Container.DataItem %> </td>
                <td>
                   <asp:DropDownList ID="DropDownList1" runat="server">
                       <asp:ListItem>111111</asp:ListItem>
                       <asp:ListItem>222222</asp:ListItem>
                       <asp:ListItem>33333333</asp:ListItem>
                       <asp:ListItem>4444444</asp:ListItem>
                   </asp:DropDownList>
                </td>
             </tr>
          </ItemTemplate>

          <FooterTemplate>
             </table>
          </FooterTemplate>

       </asp:Repeater>

       <br />

    </form>
 </body>
 </html>


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim values As New ArrayList()

            values.Add("Apple")
            values.Add("Orange")
            values.Add("Pear")
            values.Add("Banana")
            values.Add("Grape")

            ' Set the DataSource of the Repeater.
            Repeater1.DataSource = values
            Repeater1.DataBind()


            Dim values2 As New ArrayList()

            values2.Add("2Apple")
            values2.Add("2Orange")
            values2.Add("2Pear")
            values2.Add("2Banana")
            values2.Add("2Grape")

            ' Set the DataSource of the Repeater.
            Repeater1.DataSource = values
            Repeater1.DataBind()

        End If

    End Sub
0
 

Author Comment

by:PSCTECH
ID: 39766816
I appreciate the effort and all the work, but this is windows form in VB.Net.  I apologize for any confusion.
0
 
LVL 8

Expert Comment

by:5teveo
ID: 39768541
In Windows...

You may want to consider displaying DataGridView of data to include
FirstName, LastName, Shift, Phone, Department then added a button to edit record or Department.
-OR-
You find yourself re-creating a dataGridView functionality using other tools just to embed dropdown.


I use 3rd party 'GridEx' tool to perform these types of Windows interface functions. Very powerful tool.
0
 

Author Comment

by:PSCTECH
ID: 39775417
I never mentioned a grid or ASP.  It's a vb.net windows forms application and I'm asking about a combobox.
I really appreciate the effort, but I was just asking if it was do-able within those constraints.  I realize there are workarounds, but I was asking specifically about vb.net and combobox options.  I'm trying to find out if it can be done within these limits.  Again, I appreciate your comments and efforts.
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 39781088
To fill combo with data use:
'Assuming you have dtDepartment table with columns DepartmentID and DepartmentName
With cboDepartments
    .DisplayMember = "DepartmentName"
    .ValueMember = "DepartmentID"
    .DataSource = dtDepartments
'To link combo with main (Users) table, use DataBindings property (assuming bsUsers is BindingSource with users datatable
    .DataBindings.Add("SelectedValue", bsUsers, "DepartmentID")
End With

Open in new window

Here is a brief example. Add bindingnavigator (bnUsers - just to navigate through main table) , 4 lables (lblFirst,lblLast,lblShift and lblPhone and cboDepartment combobox on form.
    Private dtUsers, dtDepartments As DataTable
    Private bsUsers As BindingSource

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dtUsers = New DataTable
        dtDepartments = New DataTable
        'assign columns
        With dtUsers.Columns
            .Add("UserID", GetType(Integer))
            .Add("FirstName", GetType(String))
            .Add("LastName", GetType(String))
            .Add("Shift", GetType(String))
            .Add("Phone", GetType(String))
            .Add("DepartmentID", GetType(Integer))
        End With
        With dtDepartments.Columns
            .Add("DepartmentID", GetType(Integer))
            .Add("DepartmentName", GetType(String))
        End With
        'fill rows
        With dtUsers
            .Rows.Add(New Object() {1, "First1", "Last1", "Shift1", "Phone1", 1})
            .Rows.Add(New Object() {2, "First2", "Last2", "Shift2", "Phone2", 2})
            .Rows.Add(New Object() {3, "First3", "Last3", "Shift3", "Phone1", 3})
            .Rows.Add(New Object() {4, "First4", "Last4", "Shift4", "Phone1", 2})
            .Rows.Add(New Object() {5, "First5", "Last5", "Shift5", "Phone1", 1})
        End With
        With dtDepartments
            .Rows.Add(New Object() {1, "Department1"})
            .Rows.Add(New Object() {2, "Department2"})
            .Rows.Add(New Object() {3, "Department3"})
        End With
        'initialize bindingsource
        bsUsers = New BindingSource(dtUsers, "")
        bnUsers.BindingSource = bsUsers
        'set combo datasource
        With cboDepartments
            .DisplayMember = "DepartmentName"
            .ValueMember = "DepartmentID"
            .DataSource = dtDepartments
            'To link combo with main (Users) table, use DataBindings property
            .DataBindings.Add("SelectedValue", bsUsers, "DepartmentID")
        End With
        'Link form labels with users binding source
        lblFirst.DataBindings.Add("Text", bsUsers, "FirstName")
        lblLast.DataBindings.Add("Text", bsUsers, "LastName")
        lblShift.DataBindings.Add("Text", bsUsers, "Shift")
        lblPhone.DataBindings.Add("Text", bsUsers, "Phone")
    End Sub

Open in new window

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…
Suggested Courses

764 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