|
-
Jul 30th, 2014, 05:07 AM
#1
Thread Starter
New Member
[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!
-
Jul 31st, 2014, 09:35 AM
#2
Thread Starter
New Member
Re: DataGridView RowFilter is one keyPress behind
Noone any clue?
-
Jul 31st, 2014, 09:36 AM
#3
Re: DataGridView RowFilter is one keyPress behind
Try using the TextChanged event rather than keydown.
csharp Code:
tbox_search.TextChanged += new EventHandler(tbox_search_TextChanged); void tbox_search_TextChanged(object sender, EventArgs e) { Control ctr = (Control)sender; (dtgview.DataSource as DataTable).DefaultView.RowFilter = string.Format("{0} LIKE '%{1}%'", dtgview.Columns[ctr.TabIndex].Name, ctr.Text); }
KGC
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|