0

Can someone else who has had more caffeine than I please look at this example and tell me what I am doing wrong?

I have a custom business object called Customer and a Form1 with a BindingSource1, NumericUpDown1, TextBox1 and ComboBox1 and the attached code.

Setting break points in the Property Sets shows that the Set for the ComboBox never fires at all even though the Set for the NumericUpDown and TextBox fire like crazy.

I've obviously missed something and I know not what.

Thanks

Option Explicit On
Option Strict On
Public Class Customer
    Public Enum ChildGroup
        Infant
        Toddler
        Preschool
        GradeSchool
        HighSchool
        College
    End Enum

    Private m_Id As Int32
    Private m_Name As String
    Private m_Child As ChildGroup

    Public Sub New(ByVal id As Int32, ByVal name As String, ByVal child As ChildGroup)
        m_Id = id
        m_Name = name
        m_Child = child
    End Sub

    Public Property Id() As Int32
        Get
            Return m_Id
        End Get
        Set(ByVal value As Int32)
            m_Id = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property

    Public Property Child() As ChildGroup
        Get
            Return m_Child
        End Get
        Set(ByVal value As ChildGroup)
            m_Child = value
        End Set
    End Property
End Class

Option Explicit On
Option Strict On
Public Class Form1

    Private m_Customer As New Customer(123, "John Doe", Customer.ChildGroup.HighSchool)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BindingSource1.DataSource = Customer
        NumericUpDown1.Minimum = 0
        NumericUpDown1.Maximum = 10000
        NumericUpDown1.DataBindings.Add( _
            New Windows.Forms.Binding("Value", BindingSource1, "Id", False, _                                      DataSourceUpdateMode.OnPropertyChanged))
        TextBox1.DataBindings.Add( _
            New Windows.Forms.Binding("Text", BindingSource1, "Name", False, _                                        DataSourceUpdateMode.OnPropertyChanged))
        ComboBox1.DataBindings.Add( _
            New Windows.Forms.Binding("Text", BindingSource1, "Child", False, _                                        DataSourceUpdateMode.OnPropertyChanged))
        ComboBox1.Items.Add(Customer.ChildGroup.Infant)
        ComboBox1.Items.Add(Customer.ChildGroup.Toddler)
        ComboBox1.Items.Add(Customer.ChildGroup.Preschool)
        ComboBox1.Items.Add(Customer.ChildGroup.GradeSchool)
        ComboBox1.Items.Add(Customer.ChildGroup.HighSchool)
        ComboBox1.Items.Add(Customer.ChildGroup.College)
        ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        ComboBox1.DisplayMember = "Child"
        ComboBox1.ValueMember = "Child"
    End Sub

    Public ReadOnly Property Customer() As Customer
        Get
            Return m_Customer
        End Get
    End Property
End Class

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
0

You have to bind "SelectedItem"

..

        ComboBox1.DataSource = [Enum].GetValues(GetType(Customer.ChildGroup))
        ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
         
        BindingSource1.DataSource = Customer
        NumericUpDown1.Minimum = 0
        NumericUpDown1.Maximum = 10000
        NumericUpDown1.DataBindings.Add( _
            New Windows.Forms.Binding("Value", BindingSource1, "Id", False, DataSourceUpdateMode.OnPropertyChanged))
        TextBox1.DataBindings.Add( _
            New Windows.Forms.Binding("Text", BindingSource1, "Name", False, DataSourceUpdateMode.OnPropertyChanged))
        ComboBox1.DataBindings.Add( _
            New Windows.Forms.Binding("SelectedItem", BindingSource1, "Child", False, DataSourceUpdateMode.OnPropertyChanged))
..
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.