Hello. I'm having trouble getting a combobox bound to a property of an object. I am populating the combobox using data binding, but I can't get the SelectedValue property to bind to an object; it never gets updated. I've included my short sample below, it's from a form with just one control, a combobox named "uxChoice". The line of code giving me grief is: uxChoice.DataBindings.Add("SelectedValue", model, "SomeVariable")
Public Class Form1 Public Class anEntry Public Sub New(ByVal objectId As Integer, ByVal description As String) _objectId = objectId _description = description End Sub Private _objectId As Integer Public ReadOnly Property ObjectId() As Integer Get Return _objectId End Get End Property Private _description As String Public ReadOnly Property Description() As String Get Return _description End Get End Property End Class Private listOfChoices As anEntry() = {New anEntry(1, "A"), New anEntry(2, "B"), New anEntry(3, "C")} Public Class SomeModel Private _someVariable As Integer Public Property SomeVariable() As Integer Get Return _someVariable End Get Set(ByVal value As Integer) _someVariable = value End Set End Property End Class Private model As New SomeModel Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load uxChoice.DataSource = listOfChoices uxChoice.DisplayMember = "Description" uxChoice.ValueMember = "ObjectId" uxChoice.DataBindings.Add("SelectedValue", model, "SomeVariable") End Sub Private Sub uxChoice_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxChoice.SelectedIndexChanged If uxChoice.SelectedValue IsNot Nothing Then MsgBox(uxChoice.SelectedValue.ToString) End If MsgBox(model.SomeVariable.ToString) End Sub End Class ----------------------------------------------------- This electronic mail transmission contains information from P&H Mining Equipment which is confidential, and is intended only for the use of the proper Addressee. If you are not the intended recipient, please notify us immediately at the return address on this transmission, or by telephone at (414) 671-4400, and delete this message and any attachments from your system. Unauthorized use, copying, disclosing, distributing, or taking any action in reliance on the contents of this transmission is strictly prohibited and may be unlawful. PHUS ----------------------------------------------------- -Privacy- =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com