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. C#
  4. How do i filter in bindingsource

How do i filter in bindingsource

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • C Offline
    C Offline
    crisjala
    wrote on last edited by
    #1

    i want to filter something like string type in my textbox but my code is not working..how do i fix this private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }

    L D 2 Replies Last reply
    0
    • C crisjala

      i want to filter something like string type in my textbox but my code is not working..how do i fix this private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }

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

      According to the example on MSDN[^], you'd need to re-assign the bindinsource to the datagridview;

      // Filter the items to show contacts who are owners.
      BindingSource1.Filter = "LASTNAME='Owner'";

      // Sort the items on the company name in descending order.
      BindingSource1.Sort = "LASTNAME ASC";

      // Set the data source for dataGridView1 to BindingSource1.
      dataGridView1.DataSource = BindingSource1;

      I are Troll :suss:

      1 Reply Last reply
      0
      • C crisjala

        i want to filter something like string type in my textbox but my code is not working..how do i fix this private void button1_Click(object sender, EventArgs e) { bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text"; bindingSource1.Sort = "LASTNAME ASC"; }

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        crisjala wrote:

        bindingSource1.Filter = "LASTNAME = LIKE% + textBox1.Text";

        You might also want to pick up a book on beginners C# and work through it. It seems you have no idea how strings work. This line should be closer to

        bindingSource1.Filter = @"LASTNAME LIKE% " + textBox1.Text;
        

        though using user input directly without validating it could be considered one of the great sins of programming.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        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