【发布时间】:2013-06-08 23:27:36
【问题描述】:
我有一个数据绑定组合框 (WinForms),它在组合框失去焦点时显示 ValueMember,而不是 DisplayMember。这是我遇到此问题的一个简单示例:
Public Class Populator
Public Class Job
Property JobID As Integer
Property JobName As String
Public Sub New(ByVal id As Integer, ByVal name As String)
JobID = id
JobName = name
End Sub
End Class
Public Class Person
Property Name As String
Property JobID As Integer
Public Sub New(ByVal n As String, ByVal id As Integer)
Name = n
JobID = id
End Sub
End Class
Public Shared Function GetJobs() As List(Of Job)
Dim joblist As New List(Of Job)
joblist.Add(New Job(1, "Manager"))
joblist.Add(New Job(2, "Clerk"))
joblist.Add(New Job(3, "Unemployed"))
Return joblist
End Function
Public Shared Function GetPeople() As List(Of Person)
Dim personList As New List(Of Person)
personList.Add(New Person("Bill", 2))
personList.Add(New Person("Sally", 1))
personList.Add(New Person("Mark", 3))
personList.Add(New Person("Angie", 3))
personList.Add(New Person("Phil", 2))
Return personList
End Function
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Populator_PersonBindingSource.DataSource = Populator.GetPeople
Me.JobBindingSource.DataSource = Populator.GetJobs
End Sub
End Class
以下是一些截图:
请给我建议,当组合框失去焦点时如何保持 DisplayMember 的显示。
【问题讨论】:
标签: .net vb.net winforms data-binding combobox