473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Listview angst

My form has a listview control, set to show detail view. It has 2 columns:
workbooks and worksheets

I run the following code, trying to get each Excel workbook name as a main
item and each worksheet as a new subordinate item. Some open workbooks have
1 worksheet, but one has 11 worksheets. so, I'm expecting to see

Workbook1
worksheet1
worksheet2
Workbook2
worksheet1
worksheet2
worksheet3

and so forth

No matter what I do the listivew only shows a single line for each workbook
with that workbook's first worksheet on that same line. It's probably
something simple, but the the heck am I missing??
For Each wb In xl.Workbooks
lvi = New ListViewItem(wb.Name)
For Each ws In wb.Worksheets
lvi.SubItems.Add(ws.Name)
Next
Me.WorkbooksListview.Items.Add(lvi)
Next
Sep 14 '07 #1
1 963
Never mind - I figured out that I have to add groups. For anybody who cares,
the code I ended up using is

Dim lvi As ListViewItem = Nothing
Dim lvg As ListViewGroup = Nothing
Dim lv As ListView = Me.WorkbooksListview
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

For Each wb In xl.Workbooks
lvg = New ListViewGroup(wb.Name)
lv.Groups.Add(lvg)
For Each ws In wb.Worksheets
lvi = New ListViewItem("", lvg)
lvi.SubItems.Add(ws.Name)
lv.Items.Add(lvi)
Next

Next

"Duke Carey" wrote:
My form has a listview control, set to show detail view. It has 2 columns:
workbooks and worksheets

I run the following code, trying to get each Excel workbook name as a main
item and each worksheet as a new subordinate item. Some open workbooks have
1 worksheet, but one has 11 worksheets. so, I'm expecting to see

Workbook1
worksheet1
worksheet2
Workbook2
worksheet1
worksheet2
worksheet3

and so forth

No matter what I do the listivew only shows a single line for each workbook
with that workbook's first worksheet on that same line. It's probably
something simple, but the the heck am I missing??
For Each wb In xl.Workbooks
lvi = New ListViewItem(wb.Name)
For Each ws In wb.Worksheets
lvi.SubItems.Add(ws.Name)
Next
Me.WorkbooksListview.Items.Add(lvi)
Next
Sep 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: keith | last post by:
In a ListView control (two columns), I added a few ListView items. ListView listview=new ListView(); listview.Parent=this; listview.View=View.Details; listview.Columns.Add...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.