據我記得沒有直接的方法來添加項目做DataCombo
。 你可以考慮兩種選擇。
如果您的SQL看起來更不那麼像這樣的:
SELECT Id, Code FROM my_table
可以使用SELECT
添加artifictial記錄不FROM
子句UNION
SELECT -1 As Id, '' As Code
UNION ALL
SELECT Id, Code FROM my_table
結合第二個選項是與Combobox
和替換DataCombo
使用這樣的方法填充物品:
Public Sub Populate(ByRef pData As ADODB.Recordset, _
ByVal pIdField As String, _
ByVal pDataField As String, _
Optional pEmptyItem As Boolean = False, _
Optional pEmptyItemId As Long = -2, _
Optional pEmptyItemCaption As String = "")
If m_ComboboxControl Is Nothing Then Exit Sub
If pEmptyItem Then
m_ComboboxControl.AddItem pEmptyItemCaption
m_ComboboxControl.ItemData(m_ComboboxControl.NewIndex) = pEmptyItemId
End If
With pData
If Not (.BOF And .EOF) Then
Do While Not .EOF
Select Case TypeName(pData.Fields(pDataField).Value)
Case "Date"
m_ComboboxControl.AddItem Format(pData.Fields(pDataField), "DD-MM-YYYY")
Case Else
m_ComboboxControl.AddItem pData.Fields(pDataField)
End Select
m_ComboboxControl.ItemData(m_ComboboxControl.NewIndex) = CLng(pData.Fields(pIdField))
.MoveNext
Loop
End If
End With
End Sub