Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Search within a DataGridView

Search within a DataGridView

Scheduled Pinned Locked Moved Visual Basic
cssdatabasehelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4417354
    wrote on last edited by
    #1

    Hi I have a windows app with a datagridview and a textbox On form load I bind the grid with all records in a table. What I want to do is as I type in a textbox I want it to filter the grid to give me only what I have typed so far in the textbox.The seach will only filter on a specific colom and not on the entire grid's coloms. Cna someone help me on this, I do it this way, because I dont want to hit the DB everytime I type a letter in the textbox. Any ideas how to approach this?

    D 1 Reply Last reply
    0
    • U User 4417354

      Hi I have a windows app with a datagridview and a textbox On form load I bind the grid with all records in a table. What I want to do is as I type in a textbox I want it to filter the grid to give me only what I have typed so far in the textbox.The seach will only filter on a specific colom and not on the entire grid's coloms. Cna someone help me on this, I do it this way, because I dont want to hit the DB everytime I type a letter in the textbox. Any ideas how to approach this?

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      Bind the DataGridView to a BindingSource and use the Filter property of the BindingSource to filter the results. The Filter property acts just like a WHERE clause in SQL, so you could do; BindingSource.Filter = "ColName Like '" & textbox.text & "'" You can also then extract the filtered dataset from the source by using the following tip; http://www.codeproject.com/Tips/50317/Access-the-Data-Rows-Filtered-by-the-BindingSource.aspx[^]

      Dave Don't forget to rate messages!
      Find Me On: Web|Facebook|Twitter|LinkedIn
      Waving? dave.m.auld[at]googlewave.com

      U 1 Reply Last reply
      0
      • D DaveAuld

        Bind the DataGridView to a BindingSource and use the Filter property of the BindingSource to filter the results. The Filter property acts just like a WHERE clause in SQL, so you could do; BindingSource.Filter = "ColName Like '" & textbox.text & "'" You can also then extract the filtered dataset from the source by using the following tip; http://www.codeproject.com/Tips/50317/Access-the-Data-Rows-Filtered-by-the-BindingSource.aspx[^]

        Dave Don't forget to rate messages!
        Find Me On: Web|Facebook|Twitter|LinkedIn
        Waving? dave.m.auld[at]googlewave.com

        U Offline
        U Offline
        User 4417354
        wrote on last edited by
        #3

        Thank you so much, it seems that this will do the trick But the moment I start typing in the textbox, the grid is empty and stays empty.

        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        BindingSource.Filter = "ColName Like '" & textbox.text & "'"

        End Sub

        D L 2 Replies Last reply
        0
        • U User 4417354

          Thank you so much, it seems that this will do the trick But the moment I start typing in the textbox, the grid is empty and stays empty.

          Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

          BindingSource.Filter = "ColName Like '" & textbox.text & "'"

          End Sub

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          Depending on your data source e.g. SQL; you will need to apply suitable wild cards depending on how you want to search. You need to prefix and/or suffix the query text with a % or an *

          Dave Don't forget to rate messages!
          Find Me On: Web|Facebook|Twitter|LinkedIn
          Waving? dave.m.auld[at]googlewave.com

          1 Reply Last reply
          0
          • U User 4417354

            Thank you so much, it seems that this will do the trick But the moment I start typing in the textbox, the grid is empty and stays empty.

            Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

            BindingSource.Filter = "ColName Like '" & textbox.text & "'"

            End Sub

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Member 4420534 wrote:

            the grid is empty and stays empty

            ColName LIKE '*test'

            I are Troll :suss:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups