我有一个Listbox
调用TeachersList
,我用数据库中的字符串值填充它。现在我想删除任何导入为空的东西。当列表加载时,它会给出空白项目,我不想要这个。我尝试使用 for 循环,但它不起作用。这是我用的
int CountEmptyValues = TeachersList.Items.Count;
for (int i = CountEmptyValues - 1; i >= 0; i--)
if (TeachersList.Items[i].ToString() == " ")
{
TeachersList.Items.RemoveAt(i);
}
任何形式的帮助将不胜感激。
这是我如何将数据库中的项目添加到列表框中
MySqlConnection TeachersDB = new MySqlConnection();
string SchoolsDbString = TeachersDB.ConnectionString = @"server=localhost;Port=3306; user id=root; password=test; database=" + Globals.DBChosen;
MySqlDataAdapter SubjectsAdapter = new MySqlDataAdapter("Select " + SearchByField.Text + " From users", TeachersDB);
DataSet Dataset = new DataSet();
TeachersDB.Open();
SubjectsAdapter.Fill(Dataset);
TeachersList.DataSource = Dataset.Tables[0];
TeachersList.DisplayMember = SearchByField.Text;