Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default How populate multi-column Listbox control?

Ok, I'm back with more questions about the Listbox control. The
help documention is not very helpful, so I gotta keep asking here,
haha.

Anyways, my listbox control is set to have 3 columns, but I just can't
figure out how to put data into any column except column 1. How the
heck can I put data in columns 2 or 3???

BTW, I tried the following code which I found through Google, but it
doesn't work:

ListBox1.AddItem "here is some text"
ListBox1.List(1, 1) = "more data"
ListBox1.List(1, 2) = "even more data"

Please help. thank u


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How populate multi-column Listbox control?

When I do this kind of thing, I'm usually looping through something.

So...

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long

With Me.ListBox1
.Clear
.RowSource = ""
.ColumnCount = 3

For iCtr = 1 To 5
.AddItem "A" & iCtr
.List(.ListCount - 1, 1) = "B" & iCtr
.List(.ListCount - 1, 2) = "C" & iCtr
Next iCtr
End With
End Sub

Listcount is how many items there are (1 then 2, then 3, ..., then 5 in this
case), but the first item in the list is item 0, so we subtract 1 from the
current listcount.

Robert Crandal wrote:

Ok, I'm back with more questions about the Listbox control. The
help documention is not very helpful, so I gotta keep asking here,
haha.

Anyways, my listbox control is set to have 3 columns, but I just can't
figure out how to put data into any column except column 1. How the
heck can I put data in columns 2 or 3???

BTW, I tried the following code which I found through Google, but it
doesn't work:

ListBox1.AddItem "here is some text"
ListBox1.List(1, 1) = "more data"
ListBox1.List(1, 2) = "even more data"

Please help. thank u


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default How populate multi-column Listbox control?

Dave,

Thanks, that worked great!

BTW, do you know if I can add gridlines or something to the listbox
so I can see the dimensions of each cell in the listbox?? I almost might
want column 3 to be longer than the others.

Thanks again!

"Dave Peterson" wrote in message
...
When I do this kind of thing, I'm usually looping through something.

So...

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long

With Me.ListBox1
.Clear
.RowSource = ""
.ColumnCount = 3

For iCtr = 1 To 5
.AddItem "A" & iCtr
.List(.ListCount - 1, 1) = "B" & iCtr
.List(.ListCount - 1, 2) = "C" & iCtr
Next iCtr
End With
End Sub

Listcount is how many items there are (1 then 2, then 3, ..., then 5 in
this
case), but the first item in the list is item 0, so we subtract 1 from the
current listcount.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How populate multi-column Listbox control?

You can use ColumnCount to set the number of columns, ColumnWidths to
set the columns widths and pass an array to List for a list box. E.g.,


Private Sub UserForm_Initialize()
Dim NumRows As Long
Dim NumCols As Long
Dim Arr() As String
NumRows = 2
NumCols = 3
ReDim Arr(1 To NumRows, 1 To NumCols)
Arr(1, 1) = "r1 c1"
Arr(1, 2) = "r1 c2"
Arr(1, 3) = "r1 c3"
Arr(2, 1) = "r2 c1"
Arr(2, 2) = "r2 c2"
Arr(2, 3) = "r2,c3"
With Me.ListBox1
.ColumnCount = 3
.ColumnWidths = "100;30;30"
.List = Arr
End With
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Sat, 6 Mar 2010 13:05:36 -0700, "Robert Crandal"
wrote:

Ok, I'm back with more questions about the Listbox control. The
help documention is not very helpful, so I gotta keep asking here,
haha.

Anyways, my listbox control is set to have 3 columns, but I just can't
figure out how to put data into any column except column 1. How the
heck can I put data in columns 2 or 3???

BTW, I tried the following code which I found through Google, but it
doesn't work:

ListBox1.AddItem "here is some text"
ListBox1.List(1, 1) = "more data"
ListBox1.List(1, 2) = "even more data"

Please help. thank u

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How populate multi-column Listbox control?

I don't think Excel's listbox allows that kind of formatting.

And take a look at Chip's suggestion. He builds the array before and just loads
it in one fell swoop.

(And take note of his .columnwidths line, too.)

Robert Crandal wrote:

Dave,

Thanks, that worked great!

BTW, do you know if I can add gridlines or something to the listbox
so I can see the dimensions of each cell in the listbox?? I almost might
want column 3 to be longer than the others.

Thanks again!

"Dave Peterson" wrote in message
...
When I do this kind of thing, I'm usually looping through something.

So...

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long

With Me.ListBox1
.Clear
.RowSource = ""
.ColumnCount = 3

For iCtr = 1 To 5
.AddItem "A" & iCtr
.List(.ListCount - 1, 1) = "B" & iCtr
.List(.ListCount - 1, 2) = "C" & iCtr
Next iCtr
End With
End Sub

Listcount is how many items there are (1 then 2, then 3, ..., then 5 in
this
case), but the first item in the list is item 0, so we subtract 1 from the
current listcount.


--

Dave Peterson
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate multi-column list in worksheet not in a UserForm Afzal Excel Programming 2 June 12th 08 11:50 PM
Multi Column Listbox Help Ken Excel Programming 0 December 20th 06 10:23 PM
AddItem with multi-column listBox David Excel Programming 4 October 26th 05 05:51 PM
How to populate a multi-column activeX listbox on a spreadsheet with an ADO recordset quartz Excel Programming 1 May 3rd 04 10:13 PM
populating a multi-column Listbox Harald Staff Excel Programming 1 April 26th 04 08:26 PM


All times are GMT +1. The time now is 07:12 PM.

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"