1

我有一个数据绑定问题,基于我有一个主表单 Form1 和一个用户控件 CustomerDetails 的场景。我的主窗体上有一个网格视图,上面只有名称,并希望在我的用户控件中显示更详细的视图。

我的主窗体有一个绑定源,我的用户控件上有一个绑定源,在设计时绑定了各种字段:例如 Firstname Lastname Dob Address

我遵循了 http://msdn.microsoft.com/en-us/library/ms233813%28v=vs.90%29.aspx上的指南

这给了我正确显示的第一条记录,但是当我在我的主页面上单击其他客户时,用户控件未更新,它仍保留原始客户详细信息

代码:FORM 1

    Public Class Form1

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

            Dim CustomerList As New List(Of Customer)

            CustomerList.Add(New Customer With {.FirstName = "Fred", .LastName = "Bloggs"})
            CustomerList.Add(New Customer With {.FirstName = "John", .LastName = "Smith"})
            CustomerList.Add(New Customer With {.FirstName = "Harry", .LastName = "Davies"})
            CustomerList.Add(New Customer With {.FirstName = "Ben", .LastName = "Taylor"})
            CustomerList.Add(New Customer With {.FirstName = "Rob ", .LastName = "Jones"})

            CustomerBindingSource.DataSource = CustomerList

            End Sub
        End Class


    Code: CustomerDetails
    Imports System.ComponentModel
    <System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")>
    Public Class CustomerDetails

        ' DataMember Property
        Public Property DataMember() As Object
            Get
                Return CustomerBindingSource.DataMember
            End Get
            Set(value As Object)
                CustomerBindingSource.DataMember = value
            End Set
        End Property

        ' DataSource Property
        Public Property DataSource() As Object
            Get
                Return CustomerBindingSource.DataSource
            End Get
            Set(value As Object)
                CustomerBindingSource.DataSource = value
            End Set
        End Property
  End Class

笔记:

我正在使用设计时绑定,因此希望自动处理相关事件。

我的主窗体有一个客户列表,用户控件有详细视图。

当您在主窗体上的列表上移动时,我希望用户控件中的详细信息在它停留在第一个客户时更新?

用户控件和表单

谢谢

4

0 回答 0