清除项目后,组合框选择的值不再过滤

时间:2016-08-01 17:00:19

标签: c# combobox datagridviewcomboboxcell

我使用Combobox过滤从数据库加载的Datagridview数据。 表单加载时,datagridview和combobox会被数据填充。 Combobox没有选定的值,但是当我从下拉列表中选择一个项目时,datagridview会过滤数据。 但是,当我想通过按下按钮刷新重新开始时,只是为了在datagridview中再次加载数据,只显示过滤后的数据。

如何在触摸组合框之前获取datagridview中显示的所有数据?

到目前为止

代码......

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 
}

提前谢谢

0 个答案:

没有答案