|
-
Oct 20th, 2010, 02:11 AM
#1
Thread Starter
New Member
Need help in ListView

ok here guys is a sample picture of the output that i wanted. (note: picture is already edited)
what i wanted to do is that whenever i seach something like the example on the picture is that it will show the previous entries
for example i search for the brgy code with a code of 57252 then when you click the search it will display the upper entries in my listview as seen on the picture
how somebody can help me.. please
im using access as my database... need example codings ill just figure how you did it... thanks in advance
-
Oct 20th, 2010, 06:12 AM
#2
Re: Need help in ListView
Hi jose... Welcome to the forums...
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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 20th, 2010, 10:09 PM
#3
Thread Starter
New Member
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?
-
Oct 20th, 2010, 10:14 PM
#4
Thread Starter
New Member
Re: Need help in ListView
how can i rate your post??? its really helpful
-
Oct 21st, 2010, 02:09 AM
#5
Thread Starter
New Member
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?
-
Oct 21st, 2010, 06:03 AM
#6
Re: Need help in ListView
 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.
 Originally Posted by cpjose
how can i rate your post??? its really helpful

 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
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
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
|