Results 1 to 6 of 6

Thread: Need help in ListView

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    11

    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

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim i           As Long
    5.     Dim lngSearch   As Long
    6.     Dim lvwItem     As ListItem
    7.        
    8.     lngSearch = CLng(Text1.Text)    '~~~ Number to be searched
    9.    
    10.     For i = 1 To ListView1.ListItems.Count  '~~~ Loop through each item in the first ListView
    11.         If CLng(ListView1.ListItems(i).Text) < lngSearch Then   '~~~ Check if the item is lesser than the number to be searched
    12.             Set lvwItem = ListView2.ListItems.Add(, , ListView1.ListItems(i).Text)  '~~~ If so, add the contents to the second listview
    13.             lvwItem.SubItems(1) = ListView1.ListItems(i).SubItems(1)
    14.             lvwItem.SubItems(2) = ListView1.ListItems(i).SubItems(2)
    15.             lvwItem.SubItems(3) = ListView1.ListItems(i).SubItems(3)
    16.             lvwItem.SubItems(4) = ListView1.ListItems(i).SubItems(4)
    17.             lvwItem.SubItems(5) = ListView1.ListItems(i).SubItems(5)
    18.             Set lvwItem = Nothing
    19.         End If
    20.     Next
    21. 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,...

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    11

    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?

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    11

    Re: Need help in ListView

    how can i rate your post??? its really helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    11

    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?

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Need help in ListView

    Quote Originally Posted by cpjose View Post
    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 View Post
    how can i rate your post??? its really helpful


    Quote Originally Posted by cpjose View Post
    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:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim i           As Long
    5.     Dim lngSearch   As Long
    6.        
    7.     lngSearch = CLng(Text1.Text)    '~~~ Number to be searched
    8.    
    9.     For i = 1 To ListView1.ListItems.Count  '~~~ Loop through each item in the first ListView
    10.         If CLng(ListView1.ListItems(i).Text) > lngSearch Then   '~~~ Check if the item is greater than the number to be searched.
    11.             MsgBox ListView1.ListItems(i - 1).Text  '~~~ Assuming, the listitems are sorted in ASC order. (Right-click listview control --> Properties --> Sorting)
    12.             Exit For
    13.         End If
    14.     Next
    15. 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
  •  



Click Here to Expand Forum to Full Width