[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!
Re: DataGridView RowFilter is one keyPress behind
Noone any clue? :confused:
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