Hi Terry,
If we could custom draw the input box part of a ComboBox as well as its
items in the drop down list, a possible workaround may be custom drawing
the ComboBox to get what you want.
Unfortunately, we can not custom draw the input box part of a ComboBox.
IMO, the solution to use the Binding class's Format event to look up the
description youself you have mentioned in your first reply is good. In
addition, I think it would be better to create a custom control to
encapsulate the above logic. Then you could use this custom control
wherever you want.
The following is a sample of this custom control. Note that you shoud set
the DataSource, ValueMember and DisplayMember properties of the derived
Label before bind the Text property of the control to a data source.
Public Class MyLabel
Inherits Label
Private _datasource As IList
Private _valuemember As String
Private _displaymember As String
Public Property DataSource() As IList
Get
Return _datasource
End Get
Set(ByVal value As IList)
_datasource = value
End Set
End Property
Public Property ValueMember() As String
Get
Return _valuemember
End Get
Set(ByVal value As String)
_valuemember = value
End Set
End Property
Public Property DisplayMember() As String
Get
Return _displaymember
End Get
Set(ByVal value As String)
_displaymember = value
End Set
End Property
Sub New()
AddHandler Me.DataBindings.CollectionChanged, AddressOf
DataBindings_CollectionChanged
End Sub
Private Sub DataBindings_CollectionChanged(ByVal sender As Object,
ByVal e As System.ComponentModel.CollectionChangeEventArgs)
Dim b As Binding = CType(e.Element, Binding)
If (Not (b Is Nothing)) Then
If (b.PropertyName = "Text") Then
If (e.Action = CollectionChangeAction.Add) Then
AddHandler b.Format, AddressOf b_Format
b.ReadValue()
ElseIf (e.Action = CollectionChangeAction.Remove) Then
RemoveHandler b.Format, AddressOf b_Format
End If
End If
End If
End Sub
Private Sub b_Format(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If (Not (_datasource Is Nothing) And _datasource.Count > 0) Then
Dim pdc As PropertyDescriptorCollection =
TypeDescriptor.GetProperties(_datasource(0))
For i As Integer = 0 To _datasource.Count - 1
If (pdc(_valuemember).GetValue(_datasource(i)).ToString() =
e.Value.ToString()) Then
e.Value = pdc(_displaymember).GetValue(_datasource(i))
Exit For
End If
Next
Else
Throw New Exception("Please set the DataSource, DisplayMember
and ValueMember properties first")
End If
End Sub
End Class
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.