我已经看到了一些与我遇到的这个问题类似的问题,但它们似乎都没有解决。
我目前有一个方法,用数据库查询中的项目填充数组列表,然后返回用于填充组合框的数组列表。ComboBox 将用作其他数据库查询的搜索过滤器。
我想向数组列表添加一个空值,以便在选择空值时允许用户“关闭过滤器”。
将空值添加到数组列表时会出现问题。当我在添加数据库项目之前添加空值时,所有项目都不会显示在实际的 ComboBox 中。当我在填充 ArrayList 后添加空值时,空值永远不会在 ComboBox 中显示为一行,但其他所有内容都在那里。
public static ArrayList DropDown()
{
ArrayList status = new ArrayList();
connect.Open();
// Finds the stuff to use in the COMBO BOX
cmd.CommandText = String.Format("query");
reader = cmd.ExecuteReader();
while (reader.Read())
{
status.Add(String.Format("{0}", reader[BANK_ID]));
}
string holder = null;
status.Add(holder);
connect.Close();
return status;
}
这将导致填充的 ComboBox,但没有空行。
public static ArrayList DropDown()
{
ArrayList status = new ArrayList();
string holder = null;
status.Add(holder);
connect.Open();
// Finds the stuff to use in the COMBO BOX
cmd.CommandText = String.Format("query");
reader = cmd.ExecuteReader();
;
while (reader.Read())
{
status.Add(String.Format("{0}", reader[BANK_ID]));
}
connect.Close();
return status;
}
这导致组合框中没有任何内容。
谢谢您的帮助!