-
Sep 27th, 2021, 08:27 PM
#1
Thread Starter
Lively Member
Please how to know the number of items in a listview column?
Hello vbforums
Please can anyone help me how to tell vb6:
if there is more than one item in column1 do this.
if there only one item in column2 do this
if there no item in column3 do this
thank you all
-
Sep 27th, 2021, 09:04 PM
#2
Re: Please how to know the number of items in a listview column?
-
Sep 28th, 2021, 04:59 AM
#3
Thread Starter
Lively Member
Re: Please how to know the number of items in a listview column?
Originally Posted by dilettante
You must count them.
Would you please tell me how to do that.
For the 1st column I can use
Code:
MsgBox Listview1.Listitems.Count
What about the second and the third columns?
thank you
Last edited by Adebiyi24; Sep 28th, 2021 at 05:07 AM.
-
Sep 28th, 2021, 06:27 AM
#4
Lively Member
Re: Please how to know the number of items in a listview column?
Listview1.Columnheaders.count
Sorry, misread OP
Mods: Delete my post
-
Sep 28th, 2021, 08:25 AM
#5
Re: Please how to know the number of items in a listview column?
You have to loop through the list and check to see if there is an entry in the subitem and keep track of how many that had an entry
-
Sep 28th, 2021, 08:35 AM
#6
Thread Starter
Lively Member
Re: Please how to know the number of items in a listview column?
Originally Posted by DataMiser
You have to loop through the list and check to see if there is an entry in the subitem and keep track of how many that had an entry
thank you Mr DataMiser
Would you please provide an example.
please
-
Sep 28th, 2021, 09:22 AM
#7
Re: Please how to know the number of items in a listview column?
Listview1.Listitems.Count gives the number of the rows in the ListView
ListView1.ColumnHeaders.Count gives the number of columns in the ListView
This should give you something to work with.
It's about filling a ListView, not counting the used subitems:
Code:
Private Sub Command1_Click()
Dim oListItem As ListItem
Dim lRow As Long, lCol As Long
With ListView1
.View = lvwReport
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Column 1"
.ColumnHeaders.Add , , "Column 2"
.ColumnHeaders.Add , , "Column 3"
For lRow = 1 To 9
Set oListItem = .ListItems.Add(, , CStr(lRow))
For lCol = 1 To .ColumnHeaders.Count - 1
If Int(Rnd * 2) = 1 Then
oListItem.SubItems(lCol) = "Hello"
End If
Next lCol
Next lRow
End With
MsgBox "Number of Rows: " & CStr(ListView1.ListItems.Count) & vbLf & "Number of Columns: " & CStr(ListView1.ColumnHeaders.Count)
End Sub
-
Sep 29th, 2021, 05:11 AM
#8
Re: Please how to know the number of items in a listview column?
you can try like this to count all columns of subitems into an array
Code:
Dim cnt() As Long, i As ListItem, s As Long
With ListView1
ReDim cnt(.ColumnHeaders.Count - 2)
On Error Resume Next
For Each i In .ListItems
For s = 0 To i.ListSubItems.Count - 1
If Not i.ListSubItems(s + 1) = "" Then
cnt(s) = cnt(s) + 1
End If
Next
Next
End With
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|