ok, say i have a list of items i'd like to add to my multicolumn (2 columns) listview:
columna1
columna2
columnb1
columnb2
columnc1
columnc2
columnd1
columnd2
how would i do that... using something like a for next statement?
Printable View
ok, say i have a list of items i'd like to add to my multicolumn (2 columns) listview:
columna1
columna2
columnb1
columnb2
columnc1
columnc2
columnd1
columnd2
how would i do that... using something like a for next statement?
Clarify - you have a two column listview, and you wish to add eight more columns. Correct?
The general syntax is ...
ListView.ColumnsHeaders.Add (Index, Key, Text, Width, Alignment, Icon)
I'm sure this is not what your asking for tho ;-)
td.
no, i wish to split the text between the 2 columns
ex:
i have this to split:
columna1
columna2
columnb1
columnb2
columnc1
columnc2
columnd1
columnd2
and would like to have it like this in my listview:
columna1 columna2
columnb1 columnb2
columnc1 columnc2
columnd1 columnd2
oh, ok.
Basically your'e adding Items and each item has one Sub-Item.
General syntax is...
ListView1.ListItems.Add(Index,Key,Text,Icon, _
SmallIcon) as MSComctlLib.ListItem
and a ListItem has a property SubItems(Index) as string.
There are as many SubItems as there are columns in the ListView (remember you only see the SubItems in lvwReport view)
so... (assuming you have two columns)
Dim itm As MSComctlLib.ListItem
ListView1.view = lvwReport
set itm = ListView1.ListItems.Add (,,'Item X')
if not (itm is nothing) then itm.SubItems(1) = 'Item Y'
td.
yes, all this i am aware of =P
what i'm getting at is, i have a list of items from a parsed string in single file. what i want to do with that list is loop it to where it adds the first entry under the first column, second entry under second column, third entry under first column, fourth entry under second column and so on until my list is fully queried into the listview...
This should take a variable that contains your text file and split it into array elements using Crlf as a delimiter. Since arrays are a 0 based list (by default) then checking the int of X / 2 to the actual X / 2 will determine if it's odd or even. Due to the 0 based array, all even numbers in the array would fall under columna, while all odd numbers would fall under columnb.Code:Dim stringParse() As String
stringParse = Split(variable-containing-your-data,vbCrlf)
For X = 0 to UBound(stringParse)
If Int(X / 2) = X / 2 Then
'Place Code Here to add stringParse(X) to ColumnA
Else
'Place Code Here to add stringParse(X) to ColumnB
End If
Next X
ReDim stringParse(0)
Array(0) = Line 1
Array(1) = Line 2
...
Etc.
I hope this helps you out.
NOTE: i'm working with vb5 which does not support split
Try this:
Of course this is hard coded, since it's hard to predict what text you going to look for every time.Code:Private Sub Command1_Click()
Dim i As Integer
Dim itmList As ListItem
On Error Resume Next
With ListView1
'add column headers
.ColumnHeaders.Add Text:="Column1"
.ColumnHeaders.Add Text:="Column2"
For i = 0 To List1.ListCount - 1 Step 2
Set itmList = .ListItems.Add(, , List1.List(i))
itmList.SubItems(1) = List1.List(i + 1)
Next
End With
End Sub
cool, thanks serge... but is there a way to do it without the use of a listbox?
If you are loading a text file in during runtime, use Line Input. Keep a counter going (X = X + 1), look at X instead.
You could set up your own split function, or get one from Planet-Source-Code.Com, or check the tips section here. There is a user created VB5 version of Split somewhere ...Code:Dim FF As Integer
FF = FreeFile()
Open TEXT-FILE For Input As #FF
Do While NOT(EOF(FF))
Line Input #FF, tmpLine
X = X + 1
If Int(X / 2) = X / 2 Then
'Put your code here for ColumnB
Else
'Put your code here for ColumnA
End If
Loop
Close #FF
This Is a Quick & Dirty Split Method for VB5 that I thew together. I tested it to work, but we'll have to see ;)
[Edited by ExcalibursZone on 11-02-2000 at 04:40 PM]Code:Dim splitArray() As String
Private Sub Command1_Click()
Split tmpLine, vbCrLf
For x = LBound(splitArray) To UBound(splitArray)
MsgBox splitArray(x)
Next x
End Sub
Private Sub Split(strSplit As String, strDelim As String)
Dim splStart As Integer
Dim splEnd As Integer
Dim splCount As Integer
splCount = -1
splStart = 1
Do While InStr(splStart, strSplit, strDelim) > 0
splCount = splCount + 1
splEnd = InStr(splStart, strSplit, strDelim)
ReDim Preserve splitArray(splCount)
splitArray(splCount) = Mid(strSplit, splStart, splEnd - splStart)
splStart = splEnd + Len(strDelim)
Loop
If Len(strSplit) > splEnd Then
splCount = splCount + 1
ReDim Preserve splitArray(splCount)
splitArray(splCount) = Mid(strSplit, splStart)
End If
If splitArray(splCount) = "" Then ReDim Preserve splitArray(splCount - 1)
End Sub