1
解决方案
这是我想出了:是否可以自定义DataBound组合框的DisplayMember?
Public Class IndexedDropDownItem
Private _KeyCode, _Display As String
Public Property KeyCode() As String
Get
Return _KeyCode
End Get
Set(ByVal value As String)
_KeyCode = value
End Set
End Property
Public Property Display() As String
Get
Return _Display
End Get
Set(ByVal value As String)
_Display = value
End Set
End Property
Sub New(ByVal KeyIndex As String, ByVal ItemDisplay As String)
KeyCode = KeyIndex
Display = ItemDisplay
End Sub
Public Overrides Function ToString() As String
Return String.Format("{0} - {1}", KeyCode, Display)
End Function
End Class
实现:
With myDropDown
Dim oItem As IndexedDropDownItem = Nothing
For Each dr As Data.DataRow In oTemp.Rows
oItem = New IndexedDropDownItem(dr.Item("key_code"), _
dr.Item("descript"))
.Items.Add(oItem)
oItem = Nothing
Next
End With
手法:
Dim _KeyCode, _Display As String
With CType(dataPathComboBox.SelectedItem, IndexedDropDownItem)
_KeyCode = .KeyCode
_Display = .Display
End With
我希望这会帮助别人!
我是从一个DataTable填充的组合框:
With myComboBox
.DataSource = myDataTable
.DisplayMember = "descript"
.ValueMember = "key_code"
End With
我希望能够有将DisplayMember秀“key_code - DESCRIPT”,同时保留我已设置的值。
这甚至可能吗?由于
你能指出我朝着一个例子或样本?我想我明白你在说什么,但我想确定。 – Anders 2009-04-10 14:50:51