ListView Control

R

RLang

Hi,
I'm having a bit of trouble getting started populating a ListView control
placed on an Excel worksheet. I'm using the Microsoft ListView Control,
Version 6.0. I have Excel 2003 SP2. I've already used the same control in a
form in VB 6 with no problem. My code for setting up multiple column
headers, enabling gridlines, and adding rows of data isn't quite taking. The
same code in VB 6 is not working in VBA and I'm just looking for a little
starter help to get me going.
 
H

Harald Staff

Seeing some code would help to help. "Not working" is meaningless -unless
someone big wants his money back..

Best wishes Harald
 
R

RLang

Hi Harald, starting off simple, I'm expecting the code below to create three
columns with headers and one data line entry. This code is identical to what
I'm using in VB 6.0 to use the ListView control. The control is embedded on
the worksheet ("start") surface and is named ListView1. Right now only one
column appears with the "Rec" header title and then empty data records follow
with gridlines.

Sub CommandButton4_Click()

Dim itmX

Sheets("start").ListView1.ListItems.Clear
Sheets("Start").ListView1.ColumnHeaders.Add , , "Rec",
Sheets("Start").ListView1.Width * (3 / 5)
Sheets("Start").ListView1.ColumnHeaders.Add , , "Date/Time",
Sheets("Start").ListView1.Width * (1 / 5)
Sheets("Start").ListView1.ColumnHeaders.Add , , "Prod ID",
Sheets("Start").ListView1.Width * (1 / 5)

Set itmX = Sheets("start").ListView1.ListItems.Add()
itmX.Text = "1234"
itmX.SubItems(1) = "1/1/2008"
itmX.SubItems(2) = "890"

End Sub
 
R

RLang

Nevermind, I think I've got her working now.

RLang said:
Hi Harald, starting off simple, I'm expecting the code below to create three
columns with headers and one data line entry. This code is identical to what
I'm using in VB 6.0 to use the ListView control. The control is embedded on
the worksheet ("start") surface and is named ListView1. Right now only one
column appears with the "Rec" header title and then empty data records follow
with gridlines.

Sub CommandButton4_Click()

Dim itmX

Sheets("start").ListView1.ListItems.Clear
Sheets("Start").ListView1.ColumnHeaders.Add , , "Rec",
Sheets("Start").ListView1.Width * (3 / 5)
Sheets("Start").ListView1.ColumnHeaders.Add , , "Date/Time",
Sheets("Start").ListView1.Width * (1 / 5)
Sheets("Start").ListView1.ColumnHeaders.Add , , "Prod ID",
Sheets("Start").ListView1.Width * (1 / 5)

Set itmX = Sheets("start").ListView1.ListItems.Add()
itmX.Text = "1234"
itmX.SubItems(1) = "1/1/2008"
itmX.SubItems(2) = "890"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top