list box grid lines

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
570
Office Version
  1. 365
Is it possible in a VBA list box to view grid lines ?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
No I don't think thats possible, but if you have a Spreadsheet Control (not xl2010) you could use that, modified to look like a blank grid.
Mick
 
Upvote 0
ListView control from Microsoft Windows Common Controls 6.0 (SP6) has the property GridLines which can be set to True.
This control is not a part of Microsoft Forms 2.0 Object library.
Therefore the portability issue can happen if MSCOMCTL.OCX is not installed on PC.
BTW the same issue can happen with suggested Spreadsheet Control if it is not installed on PC.

ListView has some advantages relative to ListBox like gridlines, dragging & resizable headers, sorting and so on.

Download my example to see the differences of ListBox vs ListView: ListView_with_Headers_and_GridLines.zip
Test data are in A2:B6 cells. Press button Run on Sheet1 to show UserForm1.
The controls on UserForm1 are: ListBox1, ListView, CommantButton1.
The code of UserForm1:
Rich (BB code):

' ZVI:2011-09-25 http://www.mrexcel.com/forum/showthread.php?t=581015
Option Explicit

' Init code
' There are data in Sheet1!A2:B6 for the testing of ListBox vs ListView
' RowSource of ListBox is set to Sheet1!A2:B6, A1:B1 is used for the headers
' ListVew control is populated via below code
Private Sub UserForm_Activate()
    
  Dim a, r&, c&
  
  ' Copy range to array a()
  With Sheets(1)
    a = .Range(.Cells(.Rows.Count, "A").End(xlUp), "B1").Value
  End With
  
  ' Populate ListView
  With ListView1
    
    ' Empty ListView just for debug case
    .ListItems.Clear
    .ColumnHeaders.Clear
    
    .Sorted = True
    .Gridlines = True
    
    ' === Populate the 1st column of ListView
    c = 1
    ' Add 1st header
    .ColumnHeaders.Add , , a(1, c)
    ' Add items to the 1st column
    For r = 2 To UBound(a)
      .ListItems.Add , , a(r, c)
    Next
    
    ' === Populate the 2nd column of ListView
    c = c + 1
    ' Add 2nd header
    .ColumnHeaders.Add , , a(1, c)
    ' Add items to the 2nd column
    For r = 2 To UBound(a)
      .ListItems(r - 1).SubItems(c - 1) = a(r, c)
    Next
    
  End With
   
End Sub

' OK button's code
Private Sub CommandButton1_Click()
  Unload Me
End Sub
Regards
 
Upvote 0
Vladimir thank you I will check this and let you know, this will be allot of help :)
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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