Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: [RESOLVED] searching in text to display data with checkbox resets over and over again why?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Resolved [RESOLVED] searching in text to display data with checkbox resets over and over again why?

    hey,
    i have a listview with checkboxes that the user can choose.
    i want to search in the text box and choose some data by clicking in the checkboxes
    however
    when i start the search and find the item,i click in the checkbox
    and when i clear the textbox search the checkbox is unchecked.
    how can i make a search and checkbox what ever i want and make
    a new search but without clearing the checkbox i choosed before.
    this is my code
    Code:
        Dim Rs As New ADODB.Recordset
        Rs.Open "Select * From Inventory " & _
        " Where InvSupplier = '" & StrSuppliernameSearch & "'" & _
        " And InvItem LIKE '%" & RplS(TxtProductName.Text) & "%'" & _
        " Order By InvItem", CN
        LTreat.ListItems.clear
        Do While Not Rs.EOF
            Set itm = LTreat.ListItems.Add(, , Rs!InvItem)
            itm.SubItems(1) = FormatCurrency(Rs!InvBeforeTax)
            itm.SubItems(2) = FormatCurrency(Rs!InvForCust)
            itm.SubItems(3) = Rs!InvQuantity
            itm.SubItems(4) = FormatCurrency(Rs!InvPayments)
            itm.SubItems(5) = Rs!InvParts
            itm.SubItems(6) = Rs!Mahlakaid
        Rs.MoveNext
        Loop
        Rs.Close
    tnx for any help
    salsa

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: searching in text to display data with checkbox resets over and over again why?

    Salsa

    Your needs are a little unclear to me
    Could you post at screenshot showing an example situation?

    Spoo

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    Checkboxes are cleared each time you remove listitems. LTreat.ListItems.Clear
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by LaVolpe View Post
    Checkboxes are cleared each time you remove listitems. LTreat.ListItems.Clear
    i know sir.
    is there a way to search the listview
    check and checkbox and search again without clearing the selected one?

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by Spooman View Post
    Salsa

    Your needs are a little unclear to me
    Could you post at screenshot showing an example situation?

    Spoo
    hey spoo
    example
    lets say i have 100 items in the list ok?
    instead of searching one by onei want to search by name and check the item .
    then i want to search for another item and check it too
    but without losing the first checkbox i picked.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    You are using the same display listview also as the search mechanism, via its checkboxes? Really unclear. Maybe a screenshot of before and what is wanted after? The best answer may be to have a separate search form, instead of trying to use an ever-changing listivew as the search mechanism.

    Does your database contain a key/unique field identifier?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    Does your database contain a key/unique field identifier?
    no sir
    You are using the same display listview also as the search mechanism, via its checkboxes?
    yes
    i am loading items from the database to the listview
    the listview has checkboxes yes
    i added a textbox to search the list.
    i have like 500 items and instead of scroling the list
    i want to search the textbox to find the item.
    and then clear the textbox and search again for a diffrent item.
    so the first checkbox needs to be cheked and not cleared.

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    or maybe is there a way just to search the listview after its been loaded
    from the database

    ?

  9. #9

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    i tried this but it removes all
    Code:
        Dim X As Integer
        For X = LTreat.ListItems.Count To 1 Step -1
        Set itm = LTreat.ListItems(X)
        If LTreat.ListItems(X).Text <> TxtProductName.Text Then
            LTreat.ListItems.Remove (X)
        End If
        Next
    is there a way to use the wild card so that it will match the first word?

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: searching in text to display data with checkbox resets over and over again why?

    13aslas...you're doing it all backwards...

    Your code says to delete an item from your listview if, when going from the bottom to the top, what you are searching for is NOT found. What you MAY need is to simply change the "<>" to "="

  11. #11

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    you're doing it all backwards
    why?
    Code:
        If LTreat.ListItems(X).Text <> TxtProductName.Text Then
    look again sami
    is there a way to use the wild card so that it will match the first word?

  12. #12

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    this also dosnt work
    Code:
        Dim X As Integer
        For X = LTreat.ListItems.Count To 1 Step -1
        Set itm = LTreat.ListItems(X)
        If LTreat.ListItems(X).Text Like TxtProductName.Text Then
            LTreat.ListItems(X).Selected = True
            Exit For
        Else
            LTreat.ListItems.Remove (X)
        End If
        Next

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    LTreat.ListItems(X).Text Like TxtProductName.Text
    Use * as the wildcard in your textbox. The text box should start and end with the *

    Example: "Hello World" Like "*or*"

    Also note that this is case-sensitive. To prevent that...
    Code:
    LCase$(LTreat.ListItems(X).Text) Like LCase$(TxtProductName.Text)
    Edited: Otherwise, just use InStr() and don't mess with wildcards
    Code:
    If InStr(1, LTreat.ListItems(X).Text, TxtProductName.Text, vbTextCompare) > 0 Then ' found
    Last edited by LaVolpe; Nov 18th, 2017 at 11:59 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    still dosnt work sir
    i am doing something wrong i know

  15. #15

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    is this code ok?
    Code:
        Dim X As Integer
        For X = LTreat.ListItems.Count To 1 Step -1
        Set itm = LTreat.ListItems(X)
        If LCase$(LTreat.ListItems(X).Text) Like LCase$(TxtProductName.Text) Then
            LTreat.ListItems(X).Selected = True
            Exit For
        Else
            LTreat.ListItems.Remove (X)
        End If
        Next
    where do i add the * (wild card)?
    please help sir figure this out

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    See my updated comments in my last reply. Personally, I prefer InStr() instead of Like.

    Regarding your problem, it never helps us when someone says "it doesn't work". We need to know exactly what you expected and what actually happened, otherwise, we are forced to make assumptions. Here is my assumption... Not all items were removed that should have been removed. Is that correct? If so, it is because when you found your first match, you exited the the loop. Any other items that didn't match still remain in the list. If that is the case, simply remove the "Exit For" line.

    Edited: Regarding your question, "where do I add the wildcard". I answered that in my previous reply to you... before and after the text in your textbox. Dynamically, you could do this...
    Code:
    LCase$(LTreat.ListItems(X).Text) Like "*" & LCase$(TxtProductName.Text) & "*"
    But I'd still recommend using InStr() instead and not dealing with wildcards and not forcing LCase/UCase.
    Last edited by LaVolpe; Nov 18th, 2017 at 12:07 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    OK SIR
    i did like you say but after i check the checkbox
    and then clear the textbox search then the items that was in the listview before are gone!!
    Code:
    Private Sub TxtProductName_Change()
        Dim X As Integer
        For X = LTreat.ListItems.Count To 1 Step -1
        Set itm = LTreat.ListItems(X)
        If LCase$(LTreat.ListItems(X).Text) Like "*" & LCase$(TxtProductName.Text) & "*" Then
            LTreat.ListItems(X).EnsureVisible
        Else
            LTreat.ListItems.Remove (X)
        End If
        Next
    End Sub
    if i reload the items again from the database then the checkbox that i picked will be unchecked get it?

  18. #18
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    When you clear the listview the checkboxes are also cleared. You will have to manually check them, in code by setting the listitem's Checked property to True, when you re-add the listview items.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  19. #19
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    Hi salsa,

    I didn't go threw the complete thread, but here a sample to search threw subitem(1) of a listview

    Code:
    Private Sub Command2_Click()
    Dim i As Long
       
          With ListView1
             .MultiSelect = True
             .HideSelection = False
             .FullRowSelect = True
             For i = 1 To .ListItems.Count
    'look for salsa
                If InStr(1, .ListItems(i).SubItems(1), "salsa") > 0 Then
                   .ListItems(i).Selected = True
                Else
                   .ListItems(i).Selected = False
                End If
             Next
          End With
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  20. #20

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by ChrisE View Post
    Hi salsa,

    I didn't go threw the complete thread, but here a sample to search threw subitem(1) of a listview

    Code:
    Private Sub Command2_Click()
    Dim i As Long
       
          With ListView1
             .MultiSelect = True
             .HideSelection = False
             .FullRowSelect = True
             For i = 1 To .ListItems.Count
    'look for salsa
                If InStr(1, .ListItems(i).SubItems(1), "salsa") > 0 Then
                   .ListItems(i).Selected = True
                Else
                   .ListItems(i).Selected = False
                End If
             Next
          End With
    End Sub
    regards
    Chris
    hey chris
    i dont use a command button i use this
    Code:
    Private Sub TxtProductName_Change()

  21. #21
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    @Chris. Simply setting .Selected to true does not mark the checkbox as checked.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  22. #22
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    well that's up to you where to put a search Function/Sub

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    Salsa, is this what you are after? Note that this routine should only be called for your filtered results. Notice the one line I added (blue below)
    Code:
        Dim Rs As New ADODB.Recordset
        Rs.Open "Select * From Inventory " & _
        " Where InvSupplier = '" & StrSuppliernameSearch & "'" & _
        " And InvItem LIKE '%" & RplS(TxtProductName.Text) & "%'" & _
        " Order By InvItem", CN
        LTreat.ListItems.clear
        Do While Not Rs.EOF
            Set itm = LTreat.ListItems.Add(, , Rs!InvItem)
            itm.SubItems(1) = FormatCurrency(Rs!InvBeforeTax)
            itm.SubItems(2) = FormatCurrency(Rs!InvForCust)
            itm.SubItems(3) = Rs!InvQuantity
            itm.SubItems(4) = FormatCurrency(Rs!InvPayments)
            itm.SubItems(5) = Rs!InvParts
            itm.SubItems(6) = Rs!Mahlakaid
            itm.Checked = True
        Rs.MoveNext
        Loop
        Rs.Close
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by LaVolpe View Post
    @Chris. Simply setting .Selected to true does not mark the checkbox as checked.
    Hi,

    see change in Blue

    Code:
    Private Sub Command2_Click()
    Dim i As Long
       
          With ListView1
             .MultiSelect = True
             .HideSelection = False
             .FullRowSelect = True
             For i = 1 To .ListItems.Count
                If InStr(1, .ListItems(i).SubItems(1), "So") > 0 Then
                   .ListItems(i).Selected = True
                   .SelectedItem.Checked = True
                Else
                   .ListItems(i).Selected = False
                End If
             Next
          End With
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  25. #25

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    i am getting frustrated from my self..
    this is the whole code.
    just tell me how can i search the textbox for an item
    check the checkbox that i want and then clear the search (without the checkbox being clear)
    and then run another search in the textbox.
    this is how i load the items from the database
    Code:
    Private Sub LoadAgainItems()
        Dim Rs As New ADODB.Recordset
        Rs.Open "SELECT Inventory.InvItem, Inventory.InvForCust," & _
        " Sum(Inventory.InvRemain) AS SumOfInvRemain, Inventory.InvParts," & _
        " Inventory.InvBeforeTax, Inventory.InvQuantity, Inventory.MahlakaID" & _
        " From Inventory" & _
        " Where Inventory.InvSupplier = '" & StrSuppliernameSearch & "'" & _
        " GROUP BY Inventory.InvItem, Inventory.InvForCust," & _
        " Inventory.InvParts, Inventory.InvBeforeTax," & _
        " Inventory.InvQuantity, Inventory.MahlakaID", CN
        LTreat.ListItems.clear
        Do While Not Rs.EOF
            Set itm = LTreat.ListItems.Add(, , Rs!InvItem)
            itm.SubItems(1) = FormatCurrency(Rs!InvBeforeTax)
            itm.SubItems(2) = FormatCurrency(Rs!InvForCust)
            itm.SubItems(3) = Rs!InvQuantity
            itm.SubItems(4) = FormatCurrency(itm.SubItems(1) * itm.SubItems(3))
            itm.SubItems(5) = Rs!InvParts
            itm.SubItems(6) = Rs!Mahlakaid
            Rs.MoveNext
        Loop
        Rs.Close
    End Sub
    this is the search part
    Code:
    Private Sub TxtMozarName_Change()
        Dim X As Integer
        For X = LTreat.ListItems.Count To 1 Step -1
        Set itm = LTreat.ListItems(X)
        If LCase$(LTreat.ListItems(X).Text) Like "*" & LCase$(TxtProductName.Text) & "*" Then
            LTreat.ListItems(X).EnsureVisible
            LTreat.ListItems(X).Selected = True
            Exit For
        Else
            LTreat.ListItems.Remove (X)
        End If
        Next
        Call LoadAgainItems
    End Sub

  26. #26
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    Hi salsa,

    just use the code I gave you, change the Subitem(1) to the Subitem you want to search.

    However I would change the Sql, add the Search criteria and show just the result. Or why do
    you open everything and then perform the search ?

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  27. #27

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    hey Chris
    please see post #25

  28. #28
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    Hi,

    I did see post#25 , and it doesn't make sense.
    Think about what you are doing.
    a) you are creating a Sql with a criteria
    Code:
    " Where Inventory.InvSupplier = '" & StrSuppliernameSearch & "'" &
    b) and then you are searching for a Productname
    Code:
    If LCase$(LTreat.ListItems(X).Text) Like "*" & LCase$(TxtProductName.Text) & "*" Then
    ??? it makes no sense to me

    or can you explain why you have to search like that?

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  29. #29

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    this is my quote before
    how can i search the textbox for an item
    check the checkbox that i want and then clear the search (without the checkbox being clear)
    and then run another search in the textbox.
    this is how i load the items from the database

  30. #30
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    @Salsa, did you see post #23? If that doens't do it, then I admit that I am not understanding the question completely
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  31. #31
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,046

    Re: searching in text to display data with checkbox resets over and over again why?

    Hi Salsa,

    I just looked at LaVolpes Post#23, that will solve your problem.
    If you can't see that your problem is solved, take a break and look at it tomorrow, that's what I do when I get stuck.
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  32. #32

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by LaVolpe View Post
    @Salsa, did you see post #23? If that doens't do it, then I admit that I am not understanding the question completely
    yes sir i did didnt help me :\
    please read this
    Code:
    how can i search the textbox for an item 
    check the checkbox that i want and then clear the search (without the checkbox being clear)
    and then run another search in the textbox.

  33. #33
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    I'll take one last stab a this... This is what is wanted:

    1. You check items in the listview and create some search criteria from those checked items (your TxtProductName control)
    2. You then requery the database and on return you want:
    -- the original checked items still cheked
    -- any new items unchecked

    If the above is true, this would be so much easier if your records contained a primary/unique key. Without that, you will need to temporarily cache enough information about the checked listview items to identify them again after the listview is repopulated. Then you would go back and find each one from your cache and re-check them
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  34. #34

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    1. You check items in the listview and create some search criteria from those checked items (your TxtProductName control)
    2. You then requery the database and on return you want:
    -- the original checked items still cheked
    -- any new items unchecked
    that is correct sir!!!!!!!!!!
    this would be so much easier if your records contained a primary/unique key.
    i dont have a primary/unique key.
    Without that, you will need to temporarily cache enough information about the checked listview items to identify them again after the listview is repopulated. Then you would go back and find each one from your cache and re-check them
    how can i do that?

  35. #35
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by salsa31 View Post
    i dont have a primary/unique key.
    Add one then. Make it AutoNumber. And make sure it is returned in your query. Then this becomes a lot easier:

    1. When your listview is populated without any search criteria. Add the unique key to each list item's TAG property
    2. Now when it comes time to requery for the search criteria, your code changes just a bit...
    - the example below assumes your primary/unique key field's name is: RecordID
    -First you DO NOT clear the list items. But do remove all the unchecked ones, then
    Code:
        Dim Rs As New ADODB.Recordset
        Rs.Open "Select * From Inventory " & _
        " Where InvSupplier = '" & StrSuppliernameSearch & "'" & _
        " And InvItem LIKE '%" & RplS(TxtProductName.Text) & "%'" & _
        " Order By InvItem", CN
        ' LTreat.ListItems.clear  <<< DO NOT clear the listing
        Do While Not Rs.EOF
            If LTreat.FindItem(rs!RecordID, lvwTag) Is Nothing Then
                Set itm = LTreat.ListItems.Add(, , Rs!InvItem)
                itm.SubItems(1) = FormatCurrency(Rs!InvBeforeTax)
                itm.SubItems(2) = FormatCurrency(Rs!InvForCust)
                itm.SubItems(3) = Rs!InvQuantity
                itm.SubItems(4) = FormatCurrency(Rs!InvPayments)
                itm.SubItems(5) = Rs!InvParts
                itm.SubItems(6) = Rs!Mahlakaid
                itm.Tag = rs!RecordID
            End If
        Rs.MoveNext
        Loop
        Rs.Close
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  36. #36

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    First you DO NOT clear the list items. But do remove all the unchecked ones, then
    if i dont clear the listview then it will show double of everything

  37. #37
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searching in text to display data with checkbox resets over and over again why?

    Quote Originally Posted by salsa31 View Post
    if i dont clear the listview then it will show double of everything
    Not with the code I posted in my previous reply, if you add a primary key to your table. LTreat.FindItem(rs!RecordID, lvwTag) will only return "Nothing" if the record does not exist in your listview. This is because as each list item is added to the listview, you include the RecordID in its Tag property. Now you can see why I said it is much simpler with a primary key? We know which records are in the listview and skip re-adding them if it's already there.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  38. #38

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: searching in text to display data with checkbox resets over and over again why?

    I understand now sir
    thank you very much for your time and help
    thank you Chris.

  39. #39
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] searching in text to display data with checkbox resets over and over a

    One last thing and another tweak. I noticed your query is sorted with an Order By clause. The option I suggested won't result in a sorted list because all the checked items will be at the top and all the new items sorted below them. If that's what you want, then ok. If it's not then the following tweak can be made

    Do clear your listitems, but before doing that cache the checked RecordIDs in a collection and then go back and re-check them afterwards. This would prevent needing to remove unchecked items since the list will be cleared
    Code:
    Dim colKeys As Collection, n As Long
        Set colKeys = New Collection
        For n = 1 To LTreat.ListItems.Count
            If LTreat.ListItems(n).Checked = True Then
                colKeys.Add LTreat.ListItems(n).Tag
            End If
        Next
    
        Dim Rs As New ADODB.Recordset
        Rs.Open "Select * From Inventory " & _
        " Where InvSupplier = '" & StrSuppliernameSearch & "'" & _
        " And InvItem LIKE '%" & RplS(TxtProductName.Text) & "%'" & _
        " Order By InvItem", CN
        LTreat.ListItems.clear 
        Do While Not Rs.EOF
            Set itm = LTreat.ListItems.Add(, , Rs!InvItem)
            itm.SubItems(1) = FormatCurrency(Rs!InvBeforeTax)
            itm.SubItems(2) = FormatCurrency(Rs!InvForCust)
            itm.SubItems(3) = Rs!InvQuantity
            itm.SubItems(4) = FormatCurrency(Rs!InvPayments)
            itm.SubItems(5) = Rs!InvParts
            itm.SubItems(6) = Rs!Mahlakaid
            itm.Tag = rs!RecordID
        Rs.MoveNext
        Loop
        Rs.Close
    
        For n = 1 To colKeys.Count
            Set itm = LTreat.Find(colKeys(n), lvwTag)
            If Not itm Is Nothing Then itm.Checked = True
        Next
        Set colKeys = Nothing
    Edited: good idea but won't work for you I think. I think you want all the checked items to remain in the listview even on the 2nd and 3rd search, even if they no longer match the search criteria? Not really sure. If that's the case, then clearing the list will remove all checked items (as described), but if your new query doesn't return them, they are permanently removed. So, if this is the case and you still want your list sorted, use the logic that does not clear the list. Then sort using the listivew SortKey and Sorted properties instead of using an Order By clause. Sorry, still not 100% sure what you are looking for.
    Last edited by LaVolpe; Nov 18th, 2017 at 02:35 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  40. #40
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] searching in text to display data with checkbox resets over and over a

    Salsa

    Use of CheckBoxes is new to me, but here is something I came up with
    It doesn't match your situation directly, but it does deal with CheckBoxes

    Controls
    1. Command1 (not shown)
    2. ListView1
    3. Text2

    Concept
    • ListView is prepopulated (you can adjust as needed)
    • TextBox contains the total price of checked items


    Code snippet to update Text2 as each CheckBox is checked.

    Code:
    Private Sub ListView1_Click()
        '
        Dim itmA As ListItem
        tot = 0
        With ListView1
            For ii = 1 To .ListItems.count
                Set itmA = .ListItems.Item(ii)
                If itmA.Checked = True Then
                    vv = Val(itmA.SubItems(1))
                    tot = tot + vv
                    Text2.Text = tot
                End If
            Next ii
        End With
        '
    End Sub
    Here is screenshot

    Name:  salsa31.png
Views: 155
Size:  4.9 KB

    If a CheckBox is subsequently Unchecked, to revised total is displayed

    I can post more code if you need.
    HTH

    EDIT-1

    Wow .. a lot has transpired since I began composing this post about 2 hours ago.
    I see you've now marked it as RESOLVED
    Glad you guys worked it out.

    Spoo
    Last edited by Spooman; Nov 18th, 2017 at 03:07 PM.

Page 1 of 2 12 LastLast

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