#1   Report Post  
Posted to microsoft.public.excel.programming
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.





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ? for Tom O

I guess the correct answer to provide was the one I provided, adding - just
repopulate your textboxes, so you are working in the reverse direction.

Private Sub combobox1_Click()
With ComboBox1
Me.Controls("custnum").Value = .List(.ListIndex, 2)
Me.Controls("docnum").Value = .List(.ListIndex, 3)
Me.Controls("unitnum").Value = .List(.ListIndex, 4)
Me.Controls("expacct").Value = .List(.ListIndex, 5)
Me.Controls("expbr").Value = .List(.ListIndex, 6)
Me.Controls("amt").Value = .List(.ListIndex, 7)
Me.Controls("descr").Value = .List(.ListIndex, 9)
End With
End Sub

Basically the approach you describe.

--
Regards,
Tom Ogilvy


"Robin Hammond" wrote in message
...
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.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"