Results 1 to 3 of 3

Thread: [RESOLVED] DataGridView RowFilter is one keyPress behind

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Resolved [RESOLVED] DataGridView RowFilter is one keyPress behind

    Hi all,

    Im working with DataGridView and trying to apply TextBox(keypress) dynamic filter.
    Im using DefaultView.RowFilter with proper parameters. Filter works, but there is problem with "updating" table.

    Lets have a search word: bicycle
    When I type first letter into textbox "b" , nothing happends. When I type second letter "i", filter is set to "b" and shows appropriate results for "b".

    Code that handles textchange

    Code:
    // Assignment
    tbox_search.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dynamicFilter_KeyPress);
    
    // Keypress function
    public void dynamicFilter_KeyPress(Object sender, KeyEventArgs e)
            {
                Control ctr = (Control)sender;
    
                (dtgview.DataSource as DataTable).DefaultView.RowFilter = string.Format("{0} LIKE '%{1}%'", dtgview.Columns[ctr.TabIndex].Name, ctr.Text);
            }
    Am I missing something? Thank You for any help!

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    12

    Re: DataGridView RowFilter is one keyPress behind

    Noone any clue?

  3. #3
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: DataGridView RowFilter is one keyPress behind

    Try using the TextChanged event rather than keydown.

    csharp Code:
    1. tbox_search.TextChanged += new EventHandler(tbox_search_TextChanged);
    2.  
    3. void tbox_search_TextChanged(object sender, EventArgs e)
    4. {
    5.             Control ctr = (Control)sender;
    6.             (dtgview.DataSource as DataTable).DefaultView.RowFilter = string.Format("{0} LIKE '%{1}%'", dtgview.Columns[ctr.TabIndex].Name, ctr.Text);
    7. }

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Tags for this Thread

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