Thread: ? for Tom O
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
external usenet poster
 
Posts: 575
Default ? for Tom O

JT and Tom,

Tom, I thought you were wrong on this then went and tested it and.... right
again. Very surprising behaviour given that the combo is multi-column. So,
here's a workaround that replicates a multi-column display in the visible
portion and avoids the need for a list. The trick is to add a couple of
labels over the top of the combo.

'a way around it
'add a combo first, then two labels
'put the labels over the top of the combo and size them to
'go where the combo items would normally be displayed
'e.g reasonable values would be as follows
'cbTest.Top , cbTest.Left, cbTest.Height, cbTest.Width
' 12 18 15.75 156
'cbtest has 3 columns with column width 50
'lblCol2.Top, lblCol2.Left, lblCol2.Height, lblCol2.Width
' 15 72 12 42
'lblCol3.Top, lblCol3.Left, lblCol3.Height, lblCol3.Width
'15 114 12 48

Private Sub cbTest_Change()
With cbTest
lblCol2.Caption = .List(.ListIndex, 1)
lblCol3.Caption = .List(.ListIndex, 2)
End With
End Sub

Private Sub UserForm_Initialize()
Dim lRow As Long
Dim lDummy As Long
Dim lCol As Long
cbTest.ColumnCount = 3
For lRow = 1 To 100
cbTest.AddItem
For lCol = 1 To 3
cbTest.List(lRow - 1, lCol - 1) = lRow + lCol
Next lCol
Next lRow
cbTest.ListIndex = 0
End Sub

Robin Hammond
www.enhanceddatasystems.com

"Tom Ogilvy" wrote in message
...
Comboboxes only display one value. That is the way they work. Perhaps
you
want a listbox.

--
Regards,
Tom Ogilvy

"JT" wrote in message
...
Tom.........thanks for all of the help with comboboxes. I
haven't used them in a form before and I'm finding that
this has been quite a challenge

I've modified your suggested code to populate the combo
box. This is what I'm using

With ComboBox1

.AddItem CustNum.Value

.List(.ListCount - 1, 2) = Me.Controls("custnum").Value
.List(.ListCount - 1, 3) = Me.Controls("docnum").Value
.List(.ListCount - 1, 4) = Me.Controls("unitnum").Value
.List(.ListCount - 1, 5) = Me.Controls("expacct").Value
.List(.ListCount - 1, 6) = Me.Controls("expbr").Value
.List(.ListCount - 1, 7) = Me.Controls("amt").Value
.List(.ListCount - 1, 9) = Me.Controls("descr").Value

End With

CustNum is the first textbox the user enters data in.

However, when I click on the drop down box, I can see all
of the items in the various columns. However, when I
select a row in the combobox, only the first field is
displayed.

What can I do to display the data in all of the columns?

Any good sources for learning about comboboxes? Thanks
for all of the help, I really appreciate it.