0
我有2个组合框。当我选择/更改第一个组合框中的项目时,第二个组合框将启用。但第二个组合框总是显示我以前的项目。组合框SelectionChanged事件表明以前的项目
例如: 更改项目在组合框1和ComboBox2不显示我的任何项目。 我再次在组合框1中更改项目。现在ComboBox2显示我应该通过第一次更改显示的项目。
这里是我的代码:
private void categoryComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
subCategoryComboBox.Items.Clear();
subCategoryComboBox.IsEnabled = true;
string SelectedCategoryID = ConvertBackCategory(categoryComboBox.Text);
connection = new MySqlConnection(conf.connection_string);
if (this.OpenConnection() == true)
{
try
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = connection;
cmd.CommandText = "SELECT name FROM auftrags_typ_childcategory WHERE category = @CategoryID";
cmd.Parameters.AddWithValue("@CategoryID", SelectedCategoryID);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
subCategoryComboBox.Items.Add(reader["name"].ToString());
}
}
}
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
我怎样才能解决这个问题? /为什么它显示我不是目前的项目?
哦,谢谢。我没有在谷歌中看到这个问题,所以我虽然在这里不存在这种类型的失败.. –