locked
Change data binding in code

    Question

  • I'm have a list box where I want my data bound to a data binding source. Easy enough, just set it in properties. But I want to be able to change the values to a different binding source when I click a radio button. In other words, for each radio button I want a different set of data in my list box.

    I've tried:

         Private Sub radioButton1_Click(...)

         myListBox.BindingSource = firstBindingSource.DataSource

         myListBox.DataMember = firstBindingSource.DataMember

         End Sub

    This hasn't helped. Any suggstions?

     

    Friday, June 11, 2010 5:46 AM

Answers

  • Hi Sheldon951,

    Please try this:

    Private Sub radioButton1_Click(...)
         myListBox.DataSource = firstBindingSource
         myListBox.DisplayMember = "Col1" ' "Col1" is the column or property you want to display
    End Sub

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Sheldon951 Friday, June 18, 2010 12:50 AM
    Monday, June 14, 2010 8:29 AM
    Moderator

All replies

  • Hi Sheldon951,

    Please try this:

    Private Sub radioButton1_Click(...)
         myListBox.DataSource = firstBindingSource
         myListBox.DisplayMember = "Col1" ' "Col1" is the column or property you want to display
    End Sub

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Sheldon951 Friday, June 18, 2010 12:50 AM
    Monday, June 14, 2010 8:29 AM
    Moderator
  • Hi Alex,

    Thats exactly what I needed, it works perfectly! My mistake I think was trying to assign the BindingSource property of the list box instead of the DataSource.

    Thanks again for your help!

    Friday, June 18, 2010 12:55 AM