Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Listview to text 3

Status
Not open for further replies.

TudorSmith

Programmer
Jan 14, 2002
245
GB
Yikes...I'm having problems!

I have a Listview (listview1) on a form. I have a command button which when clicked will loop through the ocontents of the listview, and write each line in turn to a text file.

My issue is that I enter my FOR LOOP fine, but I can't seem to make the loop jump to the next item in the ListView.

All I get is an output containing only the first item from the listview!

Here's my code

Code:
Dim i As Integer
    
For Each Item In Me.ListView1.ListItems
   Debug.Print Me.ListView1.SelectedItem
   For i = 1 To Me.ListView1.ListItems.Count
        WriteLog App.Path & "\MISDLLLog.log", Me.ListView1.SelectedItem.SubItems(1)
   Next
Next

"WriteLog()" passes in my string value and outputs it to a text file. That bits fine...

If I'm oversimplifying things let me know....

Thanks

Tudor



birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Not in VB to test it right now, but try this...



For Each Item In Me.ListView1.ListItems

For i = 1 To Me.ListView1.ListItems.subitems.Count
WriteLog App.Path & "\MISDLLLog.log", item.SubItems(i)
Next
Next
 
To use the SelectedItem you need to actually select it. Just use the Index:

Dim lngCounter As Long
For lngCounter = 1 To ListView1.ListItems.Count
Debug.Print ListView1.ListItems(lngCounter).SubItems(1)
Next lngCounter


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
It's giving me an error:

"Method or Data Member Not Found" and then subitems gets highlighted

For i = 1 To Me.ListView1.ListItems.[blue]SubItems[/blue].Count

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
You will actually need to use two different loops here

Code:
Dim lListItem As ListItem
Dim lListSubItem As ListSubItem

For Each lListItem In ListView1.ListItems
    WriteLog App.Path & "\MISDLLLog.log", lListItem.Text
    For Each lListSubItem In lListItem.SubItems
        WriteLog App.Path & "\MISDLLLog.log", lListSubItem.Text
    Next
Next
 
Oh, and the reason for you error is because the SubItems collection is not part of the ListItems collection, it is only a part of a specific ListItem... not the collection of them.
 
got it cracked...thanks for all your speedy responses. They all helped!! :)

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top