>>>I used the DataCombo from MS Data List component to display a
>>>list of column item from a Table.
>>>
>>>I only can specific a column to list, as shown below.
>>>Can I list more than one columns?
>>>
>>> dcTypeItem.ListField = "ItemColumn1"
>>
>>If you want to continue to use this control, you have to concatenate fields in your SQL query (select firstname + ' ' + lastname as ItemColumns1 ...).
>>
>>You can also use the combo box from the Forms components library (Add Microsoft Forms from Project -> Components).
>
>If I would use the concatenate method. How could I expand the pull-down
>list's width to allow all the FirstName and LastName be able to display
>in the list(it is too long to fit into the list combo)?
>As the list only limit to its Combo control width and I have a space
>limit in my form. Any control Property to set to automatically expand
>according to its list items' width? Thanks.
You can use this code (taken from
http://www.mvps.org/vbnet/code/listapi/combowidth.htm):
Option Explicit
Private Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const CB_GETLBTEXTLEN = &H149
Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETDROPPEDWIDTH = &H15F
Private Const CB_SETDROPPEDWIDTH = &H160
Private Sub Command1_Click()
Dim cwidth As Long
'resize the dropdown portion of the combo box using SendMessage
Call SendMessage(Combo1.hwnd, CB_SETDROPPEDWIDTH, 250, ByVal 0)
'reflect the new dropdown list width in the Label
cwidth = SendMessage(Combo1.hwnd, CB_GETDROPPEDWIDTH, 0, ByVal 0)
'drop the list down by code to show the new size
Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
Combo1.SetFocus
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "Very long item description 1"
.AddItem "Very long item description 2"
.AddItem "Very long item description 3"
.Refresh
End With
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com