none
combobox itemssource and selectionchanged events RRS feed

  • 问题

  • 我在combobox 的loaded事件处理函数中,对itemssource进行赋值,在运行的时候,selectionchanged事件莫名被出发了,而且以后在下拉选择的时候,触发不了selectionchanged事件
    2014年9月4日 1:50

答案

  • 你好:

    从你的描述来看应该是WPF程序问题吧?我测试了下应该没有什么问题,测试代码如下:

    private void comboBox1_Loaded(object sender, RoutedEventArgs e)
            {
                using (SqlConnection conn = new SqlConnection("server=XXX.XXX.XXX.XXX;uid=sa;password=XXXXXX;database=db_test;"))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand("select * from t_users",conn))
                    {
                        DataSet set = new DataSet();
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.Fill(set);
                        comboBox1.ItemsSource = set.Tables[0].DefaultView;
                        comboBox1.DisplayMemberPath = "ID";
                    }
                }
            }
    
            private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                MessageBox.Show("Selection changed!");
            }
    应该是你别的代码或者控件的问题。


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年9月5日 11:28
    版主