Alternative to a ListBox

orangehairedboy

Board Regular
Joined
Feb 23, 2003
Messages
159
Hi all,

I'm wondering if anyone knows of a good replacement for the standard ListBox? I've currently got a listbox which has 11 columns of data in a userform, but I'd like to upgrade it so to speak.

For instance, I'd like to add gridlines, make one of the columns bold, and add some different asthetic features to it to make it more user friendly.

Does anyone know of something that I can use?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Dan,

Since I wrote it I have discovered the wonder of the ListView control and it's working great! :)

But, at least I know you were still right on the money.

Lewis
 
Upvote 0
Try a Listview, right click the toolbox toolbar and select additional controls, scroll down until you find Micosoft Listview Control Version 6.0 (I'm using WinXP and XL2k2, it might be different in your version), tick that and click ok. You will now have an extra control on the toolbox toolbar.

This is quite a different control to the listbox, take a look at help for some pointers on how to use it, it is essentially the same control that is used in Windows Explorer (right pane view), you can see your data in different views, you probably want lvwReport (look in the properties of the object).

I'll pop a couple of examples of using it at the end of this post, these are from a cell watch addin I wrote (before Microsoft added it to xl2002 :( )

The thing to note is that each row in a listview is a 'ListItem' object, and each column is a subitem (you needn't refer to col 1 as a subitem as it takes the properties of the listitem object, each subsequent column is a subitem starting at 2. Hey this isn't easy to write down, thank goodness I'm not a technical author :) Try the help, MS's technical authors are much better than me, the help is pretty good.

Regards

Z

******************************
Setting up the listview at runtime:

Private Sub UserForm_Initialize()
'===================================================================
'= Procedure: UserForm_Initialize =
'= Type: Private Subprocedure =
'= =
'= Purpose: Sets up the form, listview and data on activecell =
'= Parameters: None =
'= Returns: Nothing =
'= =
'= Version: Date: Developer: Action: =
'=---------|---------|---------------|-----------------------------=
'= 1.0.0 |17-Jan-01| Z | Created =
'===================================================================
Dim iWidth As Integer: iWidth = zCellWatch.ListView1.Width / 6
With zCellWatch
.ListView1.ColumnHeaders.Clear
.ListView1.ColumnHeaders.Add 1, "book", "Book", iWidth
.ListView1.ColumnHeaders.Add 2, "sheet", "Sheet", iWidth
.ListView1.ColumnHeaders.Add 3, "name", "Name", iWidth
.ListView1.ColumnHeaders.Add 4, "cell", "Cell", iWidth
.ListView1.ColumnHeaders.Add 5, "value", "Value", iWidth
.ListView1.ColumnHeaders.Add 6, "formula", "Formula", iWidth
.ListView1.LabelEdit = lvwManual
End With
End Sub
***************************************


Adding items to a listview:

Sub AddWatch(objCell As Range)
'===================================================================
'= Procedure: AddWatch =
'= Type: Subprocedure =
'= =
'= Purpose: Populates the lstview object with the info about =
'= the selected cell =
'= Parameters: objCell - Range - =
'= Returns: Nothing =
'= =
'= Version: Date: Developer: Action: =
'=---------|---------|---------------|-----------------------------=
'= 1.0.0 |17-Jan-01| Z | Created =
'===================================================================
Dim itmX As ListItem
Dim rngCell As Range
For Each rngCell In objCell
With zCellWatch
Set itmX = .ListView1.ListItems.Add(.ListView1.ListItems.Count + 1, , ActiveWorkbook.Name)
itmX.SubItems(1) = ActiveWorkbook.ActiveSheet.Name
On Error Resume Next
itmX.SubItems(2) = rngCell.Name.Name
itmX.SubItems(3) = rngCell.Address
itmX.SubItems(4) = rngCell.Value
itmX.SubItems(5) = rngCell.Formula
.ListView1.View = lvwReport
.ListView1.SelectedItem.Selected = False
.Show
End With
Next
End Sub
*************************************
 
Upvote 0
Yes, I think they crossed in the post so to speak, when I started typing mine, you had no answers, so I thought I'd help.

Just one of those things.

Z
 
Upvote 0

Forum statistics

Threads
1,203,667
Messages
6,056,643
Members
444,879
Latest member
suzndush

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top