DataGridView First Row Lost When I Filter It

Posted by Surendrasinh under C# on 10/1/2013 | Points: 10 | Views : 1635 | Status : [Member] | Replies : 0
hi Developers,
I am creating winform application.In that i have a DataGridview.I want to keep first row as filter row,so user can write and filter rows.I have coded something like following.It works but when it filter it loss my filter row.Please give me any suggestion.Thanks in advance.

Private Void LoadGridData()
{
dataGridView.DataSource = table;
table.Rows.InsertAt(table.NewRow(), 0);
dataGridView.Rows[0].Frozen = true;
dataGridView.Rows[0].ReadOnly = false;
dataGridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView_EditingControlShowing);
}

private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{
txt_edit = e.Control as TextBox;
if (txt_edit != null)
{
txt_edit.TextChanged += new EventHandler(TextChangedEventHandler);
}
}
//((DataTable)dgvData.DataSource).DefaultView.RowFilter = filter;
private void TextChangedEventHandler(object sender, EventArgs e)
{
try
{
string columnName = dataGridView.CurrentCell.OwningColumn.Name.ToString();
DataView dv = ((DataTable)dataGridView.DataSource).DefaultView;
dv.RowStateFilter = DataViewRowState.Unchanged;
dv.RowFilter = "Convert(" + columnName + ", 'System.String') LIKE '%" + txt_edit.Text + "%'";
}
catch (Exception ex)
{
throw ex;
}
}




Responses

(No response found.)

Login to post response