Results 1 to 9 of 9

Thread: Search data from a Gridview or Dataset.

Hybrid View

  1. #1
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: Search data from a Gridview or Dataset.

    You could have another datatable and when the Search Text changes, copy the matching rows from the original to the shown datatable (or just unhook the DGV from the original dt and manually fill it each time.
    Or set unmatched rows to visible=false in the DGV, if that's possible.

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

    Re: Search data from a Gridview or Dataset.

    Quote Originally Posted by geek648 View Post
    You could have another datatable and when the Search Text changes, copy the matching rows from the original to the shown datatable (or just unhook the DGV from the original dt and manually fill it each time.
    Or set unmatched rows to visible=false in the DGV, if that's possible.
    Definitely don't do that.

    The proper way to do this is via a BindingSource. Populate your DataTable, bind that to a BindingSource and then bind that to the DataGridView (NOT GridView, which is a different control altogether). To filter the data, simply set the Filter property of the BindingSource, e.g.
    Code:
    myBindingSource.Filter = String.Format("SomeColumn LIKE '{0}%'", myTextBox.Text)
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2012
    Posts
    100

    Re: Search data from a Gridview or Dataset.

    Hello jmcilhinney,

    You 're simply genius, that resolved and that too with the most effective solution.
    Thanks a lot

  4. #4
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: Search data from a Gridview or Dataset.

    Quote Originally Posted by jmcilhinney View Post
    Definitely don't do that.

    The proper way to do this is via a BindingSource.
    Well at least I can serve as an example of how not to do it, LOL.
    I'll get my coat.

    Thanks for educating me

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

    Re: Search data from a Gridview or Dataset.

    Quote Originally Posted by geek648 View Post
    Well at least I can serve as an example of how not to do it, LOL.
    I'll get my coat.

    Thanks for educating me
    Getting it wrong is usually the first step on the road to getting it right.
    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

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