Results 1 to 18 of 18

Thread: [RESOLVED] .RowFilter search multiple words

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Resolved [RESOLVED] .RowFilter search multiple words

    Hi,

    Im using datagridview with

    Code:
    .RowFilter = "loc like '%" + txtSearchT.Text + "%'"
    Everything works fine when i filter one word but when i write in the txtSearchT box something like "find this" (multiple words) i get errors.

    Is there a solution to that that would be straight forward or a solution would be to split the string in arrays and then to search them with OR / AND operators in the row filter string?


    Cheers!
    Thanks for helping me out.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .RowFilter search multiple words

    what kind of errors are you getting because
    loc like '%find this%'
    is perfectly valid. Perhaps there is something else that is wrong.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    well if a record value is : "one-half-four" and i input in search "one four" i get this error :

    Value of "-1" is not valid for "Maximum". "Maximum" must be greater than or equal to 0. Parameter name: Maximum
    Thanks for helping me out.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: .RowFilter search multiple words

    Er ... where does 'Maximum' come into this? I thought you were searching on values of 'loc'?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    on form load :
    Code:
    ds = New DataSet()
    dv = New DataView()

    button to search:
    Code:
     
                    ds.Clear()
                    Dim path As String = Application.StartupPath & "\data.xml"
                    ds.ReadXml(path)
                    dv.Table = ds.Tables(0)
                    DataGridView1.DataSource = dv
                    dv.RowFilter = "loc like '%" + txtSearchT.Text + "%'"
    i get to find one word or one word that follows the other and matches a record...
    Thanks for helping me out.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .RowFilter search multiple words

    well the error has nothing to do with your row filter... but judging by the error message, it sound like you're trying to use the .RecordCount to set on the .Maximum property of a progress bar or something... and the count is coming back as -1...

    Even still ... if you search for "one four" it will NOT find "one-half-four" ... it wouldn't even find "one-four" ... if you want it to, then you would need to replace the spaces in the string with the % wildcard as well... so you end up with '%one%four%' ... then it would match "one-half-four".

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: .RowFilter search multiple words

    Ok. That still doesn't make any more sense of the error you're getting but the main problem is that you misuse the LIKE clause. Using your example ... One Half Four (although I've no idea what it means!) One%, %Half%, %Four will all get matches but %One Four% won't because it requires recognition that there is an implied wild card represented by the space and the parser just isn't that sophisticated. Neither can you have an explicit wild card in the middle of a LIKE string. When tg said that %find this% would work he was assuming that the complete value was something like "You find this in Kansas".

    EDIT: I have so got to learn to type faster!!!

    EDIT EDIT: Oh wait, tg got it wrong. Tee hee! Let's see if he notices!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    EDIT:

    let me read your post too

    EDIT:

    Ok, let's say my record is:

    One-Two-Four-Five

    So when i search for "one" i will get the result, when i search "one five" i wont get any results.

    So, as dunfiddling said i wont be able to do it with adding wildcards?
    Last edited by batori; May 20th, 2013 at 08:12 PM.
    Thanks for helping me out.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .RowFilter search multiple words

    did you read post #6 where I said
    Quote Originally Posted by me
    you would need to replace the spaces in the string with the % wildcard as well... so you end up with '%one%four%' ... then it would match "one-half-four".
    you CAN put wildcards in the middle... I do it all the time... I wouldn't be able to search half the things I do w/o being able to.... that being said... I don't usually use the rowFilter so I don't know if it plays by different rules or not.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: .RowFilter search multiple words

    I don't know if it plays by different rules or not
    You do now! A wildcard in the middle will get you an invalid string error every time!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .RowFilter search multiple words

    well that's just silly... what good it is then?

    it seems the general recommendation is to use the .Select method instead...
    https://www.google.com/search?q=how+...able+in+vb.net

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .RowFilter search multiple words

    Quote Originally Posted by techgnome View Post
    well that's just silly... what good it is then?

    it seems the general recommendation is to use the .Select method instead...
    https://www.google.com/search?q=how+...able+in+vb.net

    -tg
    This:
    Code:
    SomeColumn LIKE %x%y%
    is functionally equivalent to this:
    Code:
    SomeColumn LIKE %x% AND SomeColumn LIKE %y%
    so it's generally not an issue. It only becomes a problem when there is some overlap between the two literals, e.g. this:
    Code:
    SomeColumn LIKE %wxy%xyz%
    is not the same as this
    Code:
    SomeColumn LIKE %wxy% AND SomeColumn LIKE %xyz%
    You can still get around that too, although it makes the code more complex again and building the code becomes complex too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    Tried to use this : "SomeColumn LIKE %wxy%xyz%" but what i was getting is all the record back as i never searched them.
    Thanks for helping me out.

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .RowFilter search multiple words

    Quote Originally Posted by jmcilhinney View Post
    This:
    Code:
    SomeColumn LIKE %x%y%
    is functionally equivalent to this:
    Code:
    SomeColumn LIKE %x% AND SomeColumn LIKE %y%
    I beg to differ... if the search is %one%four% ... and the string is "four one" ... that's not a match....
    but if the search is %one% AN %four% then "four one" is a match even though it's "out of order" because it's looking for each search term separately and not together.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    This is what i'm doing now:
    Record is : One-Two-Four-Five
    The code is :
    Code:
    loc LIKE '%one% AND loc LIKE %four%'
    Still, i get all the records listed, not the one searched. I'm not sure why ...
    Thanks for helping me out.

  16. #16
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: .RowFilter search multiple words

    loc LIKE '%one%' AND loc LIKE '%four%'
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: .RowFilter search multiple words

    Quote Originally Posted by techgnome View Post
    I beg to differ... if the search is %one%four% ... and the string is "four one" ... that's not a match....
    but if the search is %one% AN %four% then "four one" is a match even though it's "out of order" because it's looking for each search term separately and not together.

    -tg
    B*gger! Didn't think of that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: .RowFilter search multiple words

    Quote Originally Posted by dunfiddlin View Post
    loc LIKE '%one%' AND loc LIKE '%four%'
    Thank you very much, it works.

    Im using this, if anyone needs it :

    Code:
    dv.RowFilter = "loc like '%" & Replace(txtSearchT.Text, " ", "%' AND loc LIKE '%") & "%'"

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