I have a few TextBox
es and I use this code for textchange events to search:
DataView dvTelbook = dtTelbook.DefaultView;
dvTelbook.RowFilter = "[name] LIKE '%" + textBox.Text + "%'";
That code works well and when I use that TextBox
to search in a DataGridView
(filtered by name) it works so far.
My problem is:
When I click the reset button, the DataGridView
can't reload.
I want to reload the DataGridView
after search, exactly like when first loading the Form
.
But datagridview.refresh();
does not work and datagridview.datasource = "null"
clears my DataGridView
. And when I use datagridview.datasource = mydata();
the DataGridView
loads again but all data is duplicated.
Any suggestions?
To stop the duplication, do:
datagridview.datasource = "null"
followed by:
datagridview.datasource = mydata();
i find solution .
see my reset form code :
private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
// this line work and clear my datagrid view
dataGridView1.Columns.Clear();
//this line cant work and my datagridview is blank
dataGridView1.DataSource = mydata();
}
that code is wrong . i use this code as solution :
i use this private DataTable myname = new DataTable(); after that : i use myname.Reset();
in button 3 click.
see button3 click code :
textBox1.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
myname.Reset();
dataGridView1.DataSource = mydata();
DataView test = myname.DefaultView;
test.RowFilter = string.Empty;
and done . my result refresh good and dont duplicated .
good luck
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.