set combobox display member and value member at run-tiem

Juan Velasquez
Juan Velasquez used Ask the Experts™
on
Hello,  
I am using the following code to populate a combobox at runtime.  I now need to set the display member and value members.  For example I would neet to set
cboSelectBudget.value member to bud.budget and cboSelectBudget.DisplayMember to bud.budgetdescription
Private Sub LoadBudgetComboBox()
        Try
            BudgetList = BudgetDB.GetBudgetList
            cboSelectBudget.Items.Clear()                  
      
            For Each bud As Budget In BudgetList
                cboSelectBudget.Items.Add(bud.Budget).ToString()


            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
        End Try
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015

Commented:
Maybe?
cboSelectBudget.Items.Add(New DataDescription(bud.Buget, bud.datadescription))
Private Sub LoadBudgetComboBox()
        Try
            BudgetList = BudgetDB.GetBudgetList

            cboSelectBudget.DataSource = BudgetList
            cboSelectBudget.DisplayMember = "BudgetDescription"
            cboSelectBudget.ValueMember = "Budget"
           
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)
        End Try
    End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial