我没有解决这个问题。
我有几个comboboxes
从sql
获取值来过滤表中的某些数据,问题是当用户选择combobox
时,如果他想清除它,则无法选择所以,只选择另一个项目。
经过一些搜索,我添加了button
来清除comboboxes
,但我不想要那个解决方案,我想的是在每个组合框中创建一个空白区域来清除选择。
如何创建这样的空间,用户可以选择是否要删除选择。 代码:
private void vidro_Load(object sender, EventArgs e)
{
SqlDataAdapter SDA = new SqlDataAdapter("select distinct desempenho from vidros", con);
DataTable DTT = new DataTable();
SDA.Fill(DTT);
desempenho.Items.Clear();
foreach (DataRow ROW in DTT.Rows)
{
desempenho.Items.Add(ROW["desempenho"].ToString());
}
SqlDataAdapter SDA2 = new SqlDataAdapter("select distinct valu from vidros", con);
DataTable DTT2 = new DataTable();
SDA2.Fill(DTT2);
valu.Items.Clear();
foreach (DataRow ROW in DTT2.Rows)
{
valu.Items.Add(ROW["valu"].ToString());
}
SqlDataAdapter SDA3 = new SqlDataAdapter("select distinct fs from vidros", con);
DataTable DTT3 = new DataTable();
SDA3.Fill(DTT3);
fsolar.Items.Clear();
foreach (DataRow ROW in DTT3.Rows)
{
fsolar.Items.Add(ROW["fs"].ToString());
}
SqlDataAdapter SDA5 = new SqlDataAdapter("select distinct compo from vidros", con);
DataTable DTT5 = new DataTable();
SDA5.Fill(DTT5);
select.Items.Clear();
foreach (DataRow ROW in DTT5.Rows)
{
compo.Items.Add(ROW["compo"].ToString());
}
SqlDataAdapter SDA6 = new SqlDataAdapter("select distinct sel from vidros", con);
DataTable DTT6 = new DataTable();
SDA6.Fill(DTT6);
select.Items.Clear();
foreach (DataRow ROW in DTT6.Rows)
{
select.Items.Add(ROW["sel"].ToString());
}
}
private void compo_SelectedIndexChanged_1(object sender, EventArgs e)
{
FillData();
}
private void select_SelectedIndexChanged(object sender, EventArgs e)
{
FillData();
}
private void fsolar_SelectedIndexChanged_1(object sender, EventArgs e)
{
FillData();
}
private void valu_SelectedIndexChanged_1(object sender, EventArgs e)
{
FillData();
}
private void desempenho_SelectedIndexChanged_1(object sender, EventArgs e)
{
FillData();
}
private void FillData()
{
string combo1value = desempenho.Text;
string combo2value = valu.Text;
string combo3value = fsolar.Text;
string combo4value = select.Text;
string combo5value = compo.Text;
string query = "select [descri],[enchimento],[compo] from vidros where 1=1 ";
string queryWhere = "";
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
sda.SelectCommand = cmd;
提前致谢
答案 0 :(得分:1)
让我们以你的一个组合框为例:
desempenho.Items.Clear();
foreach (DataRow ROW in DTT.Rows)
{
desempenho.Items.Add(ROW["desempenho"].ToString());
}
desempenho.Items.Items.Insert(0,"");
这样你的组合中第一个空项目,然后你必须在验证表格时检查它。