I use Combobox to filter Datagridview data loaded from a database. When form loads, datagridview and combobox get filled by data. Combobox doesn't have selected values, but when I choose an item from a dropdown, datagridview filters data just fine. But, when I want to start over by pressing button refresh, just to load data again in datagridview, only filtered data is shown.
How to get all data shown in datagridview before touching combobox?
Code so far...
private void form1_load(object sender, EventArgs e)
{
this.comboBox1.SelectedIndexChanged +=new System.EventHandler(comboBox1_SelectedIndexChanged);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
dv = dt.DefaultView;
dv.RowFilter=string.Format("Status LIKE '%{0}'", comboBox1.SelectedItem.ToString());
dataGridView1.DataSource = dv;
}
private void button1refresh_Click(object sender, EventArgs e)
{
comboBox1.DataSource = null; //doesn't work
comboBox1.Text = ""; //clears first item in combobox, but still filters
comboBox1.Items.Clear(); //clears items but still filters
comboBox1.SelectedIndex = -1; //sets combobox to -1, but filters
comboBox1.ResetText(); //doesnt work
dt.Clear();
dataGridView1.DataSource = null;
dataGridView1.Rows.Clear();
dataGridView1.Refresh();
FilllData(); //invoke function to fill the datagridview again and combobox
//this function works great at first run, but after clicking on refresh, it show's only filtered data
}
Thank you in advance