Results 1 to 14 of 14

Thread: [RESOLVED] Filtering datagrid data from textbox input

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Resolved [RESOLVED] Filtering datagrid data from textbox input

    Hi there, I have been away from programming for a while, so cannot quite remember how to filter a data grid using a textbox. Below is the code that I have (but throws an error):

    TestFilterdatagridBindingSource.Filter = "FlightPlan Code ='" & TextBox1.Text & "'"

    Can anyone please help with this?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    try:

    Code:
    TestFilterdatagridBindingSource.Filter = "[FlightPlan Code] ='" & TextBox1.Text & "'"

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    if it's a numeric field, don't use the surrounding '

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    Thanks for reply, but I still get a error:Name:  Error.JPG
Views: 189
Size:  26.6 KB

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    did you see post #3?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    that would be:

    Code:
    TestFilterdatagridBindingSource.Filter = "[FlightPlan Code] =" & TextBox1.Text

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    Yes, but still not liking this without the surrounding '
    I am at a loss here??

    Name:  Error 2.jpg
Views: 184
Size:  19.1 KB

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    you removed the =

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    This still gets an error:

    Name:  Error 3.jpg
Views: 120
Size:  17.2 KB

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    This is the last code I tried:
    TestFilterdatagridBindingSource.Filter = "[FlightPlan Code] =" & TextBox1.Text

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    At the time that you clicked the button, what was TextBox1.Text?
    If it was "" that would explain the error

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    Quote Originally Posted by .paul. View Post
    At the time that you clicked the button, what was TextBox1.Text?
    If it was "" that would explain the error
    The contents of textbox1.text contains a test number of "1234"

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Filtering datagrid data from textbox input

    If you need "" to equal all records, try:

    TestFilterdatagridBindingSource.Filter = "[FlightPlan Code] LIKE " & If(TextBox1.Text = "", "%", TextBox1.Text)

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    234

    Re: Filtering datagrid data from textbox input

    Thanks for your help, my mistake, I missed the fact that I had changed the textbox1 to textbox3. you were correct textbox1 had NO contents.
    Really sorry to waste your time, and thanks for your help

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