Re: Need help in ListView
Hi jose... Welcome to the forums...:wave:
One way is to query the database for selecting records which have the brgy code lesser than the one being searched. Then, display the records in a ListView control.
Second way is to loop through all the items in the first listview(which will be filled with the entire data) and add the low valued brgy code items to the second listview control.
Example:
vb Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim lngSearch As Long
Dim lvwItem As ListItem
lngSearch = CLng(Text1.Text) '~~~ Number to be searched
For i = 1 To ListView1.ListItems.Count '~~~ Loop through each item in the first ListView
If CLng(ListView1.ListItems(i).Text) < lngSearch Then '~~~ Check if the item is lesser than the number to be searched
Set lvwItem = ListView2.ListItems.Add(, , ListView1.ListItems(i).Text) '~~~ If so, add the contents to the second listview
lvwItem.SubItems(1) = ListView1.ListItems(i).SubItems(1)
lvwItem.SubItems(2) = ListView1.ListItems(i).SubItems(2)
lvwItem.SubItems(3) = ListView1.ListItems(i).SubItems(3)
lvwItem.SubItems(4) = ListView1.ListItems(i).SubItems(4)
lvwItem.SubItems(5) = ListView1.ListItems(i).SubItems(5)
Set lvwItem = Nothing
End If
Next
End Sub
:wave:
Re: Need help in ListView
thanks man it works.... can i have another question ?? how can i set the limit to that for up to 3 display only
for example i have this in my database
1
2
3
4
5
6
7
8
9
10
and my selection would be number 5
i wanted to output 4,3,2 only cause i have to limit it to output 3 entries per selection only?
Re: Need help in ListView
how can i rate your post??? its really helpful
Re: Need help in ListView
follow up question:
my selected item in the picture would be 57252 and i wanted to display in the listview2 the item before him which is 57251. how am i going to do that???
never mind the Brgy Code because it is not arrange according to it.
another question would be :
what if my chosen entry would be the first one in the list which is 58894
and the output for the UP: labeled listview would be the last item in the listview which is 57344 going up to 57252?
Re: Need help in ListView
Quote:
Originally Posted by
cpjose
thanks man it works.... can i have another question ?? how can i set the limit to that for up to 3 display only
i have to limit it to output 3 entries per selection only?
Use the below code inside the FOR loop.
Code:
If ListView2.ListItems.Count = 3 Then Exit For
The code will check if the number of items in the second ListView control reaches 3. If so, exit the loop.
Quote:
Originally Posted by
cpjose
how can i rate your post??? its really helpful
http://i660.photobucket.com/albums/u...tethispost.png
Quote:
Originally Posted by
cpjose
follow up question:
my selected item in the picture would be 57252 and i wanted to display in the listview2 the item before him which is 57251. how am i going to do that???
vb Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim lngSearch As Long
lngSearch = CLng(Text1.Text) '~~~ Number to be searched
For i = 1 To ListView1.ListItems.Count '~~~ Loop through each item in the first ListView
If CLng(ListView1.ListItems(i).Text) > lngSearch Then '~~~ Check if the item is greater than the number to be searched.
MsgBox ListView1.ListItems(i - 1).Text '~~~ Assuming, the listitems are sorted in ASC order. (Right-click listview control --> Properties --> Sorting)
Exit For
End If
Next
End Sub
:wave: