Results 1 to 2 of 2

Thread: [2005] Help with using TableLayoutPanel and dynamic Combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    69

    [2005] Help with using TableLayoutPanel and dynamic Combobox

    Ok, I need some serious help with this. I've searched on the forums, googled, and expermimented as much as I can....all to no avail.

    Here's the problem.

    I'm using a TableLayoutPanel to dynamically configure a form based on values from a database. To the TableLayoutPanel, I dynamically add 1 Label, 1 Textbox, 1 Button, and 1 Combobox. Here's the root of the problem, If I have 2 or more rows in the TableLayoutPanel, ALL the Comboboxes change at the same time.

    What do I have to do to only get 1 Combobox to change at a time??

    Here's the code I'm using
    Code:
     If lobjDS.Tables(0).Rows.Count > 0 Then
                Me.TableLayoutPanel1.SuspendLayout()
                For Each dr As DataRow In lobjDS.Tables(0).Rows
                    llbl = New Label
                    With llbl
                        .Text = dr("Description") & ":"
                        .Margin = New Padding(2, 2, 2, 2)
                        .TextAlign = ContentAlignment.MiddleRight
                        .Dock = DockStyle.Fill
                        .AutoSize = True
                    End With
    
                    lCombobox = New ComboBox
                    With lCombobox
                        .Dock = DockStyle.Fill
                        .DisplayMember = "Description"
                        .ValueMember = "Value"
                        .DataSource = VDPOperators
                    End With
    
                    lTextbox = New TextBox
                    With lTextbox
                        .Dock = DockStyle.Fill
                    End With
    
                    lButton = New Button
                    With lButton
                        .Text = "AND"
                        .Height = 22
                        .Width = 38
                    End With
    
                    With Me.TableLayoutPanel1
                        .Controls.Add(llbl)
                        .Controls.Add(lCombobox)
                        .Controls.Add(lTextbox)
                        .Controls.Add(lButton)
                    End With
                Next
    
                Me.TableLayoutPanel1.ResumeLayout()
    Thanks for any suggestions!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Help with using TableLayoutPanel and dynamic Combobox

    What do you mean by "ALL the Comboboxes change at the same time"? Are you saying that if you change the selection in one ComboBox the selection changes in the others too? If so then your use of a TableLayoutPanel is not relevant to the problem. The issue would be that you're binding them all to the same data source, so there's only one CurrencyManager. If there's one CurrencyManager then there's one Current item, and it will be shown in all the ComboBoxes. What you need to do is create a new BindingSource for each new ComboBox. Bind your data to the BindingSource and the BindingSource to the control. Now each control has a different CurrencyManager so they can each have an independent selection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width