Results 1 to 7 of 7

Thread: share data between 2 combo boxes in 2 different forms

  1. #1
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15

    share data between 2 combo boxes in 2 different forms

    Dear forummembers,

    I have a Form1 with a combobox1 and knop1.
    I have a Form2 with combobox2 and knop2.
    combobox1 shows values ​​that can be selected.
    when the button is pressed from Form1 I want Form2 opens with the
    combobox2 the selected value from combobox1.
    knop2 when pressed on the same happens with combox1 from Form1.

    I've looked on the web, but couldn't find a solution.

    Suggestions? How can I handle this?

    Txs.

    John

  2. #2
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    Code:
    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Form2.ComboBox1.SelectedItem = Me.ComboBox1.SelectedItem
            Form2.Show()
        End Sub
    End Class
    Code:
    Public Class Form2
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Form1.ComboBox1.SelectedItem = Me.ComboBox1.SelectedItem
            Me.Close()
        End Sub
    End Class

  3. #3
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15
    Txs for the reply but it doesn't work.
    Other suggestions?

    John

  4. #4
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    It does work. I didn't just type it out of my head, I tested it! If it doesn't work in your project then it's either because you didn't apply it correctly or there are other factors that are affecting it. Had you bothered to include your version of the code rather than sitting there with your mouth open expecting another spoon of soup I might be able to determine that!

  5. #5
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15
    Txs Dunfiddlin,

    If it works than there are other factors.
    I'm testing and when I found something I let it know.

    John.

  6. #6
    VBobCat's Avatar
    VBobCat is offline VB.NET Forum Fanatic
    .NET Framework
    .NET 4.0
    Join Date
    Sep 2011
    Location
    São Paulo, Brazil
    Posts
    117
    Reputation
    25
    Maybe the reason Dunfiddlin's suggestion doesn't work on JohnDW project is because it assumes ComboBox1 and ComboBox2 have the same identical datasource, so that they have equally typed items as children, and one's .SelectedItem underlying object could be assigned to the other's .SelectedItem. Maybe replacing "Form2.ComboBox1.SelectedItem = Me.ComboBox1.SelectedItem" with "Form2.ComboBox1.SelectedValue = Me.ComboBox1.SelectedValue" would make it, but only if both comboboxes have its .ValueMember properties set to the same column of datasource. I hope it helps.

  7. #7
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    Yes, I did assume that the conboboxes were identical. It didn't make a lot of sense as an idea if they weren't but I suppose you gotta learn to expect the unexpected around these parts!

Bookmarks

Posting Permissions

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