0

我有 ListBox 控件(WinForm 项目)。

当我将 DataSource 绑定到 ListBox 控件时,会触发 listBox_SelectedIndexChanged 事件。

这是代码:

公共 Form1() { InitializeComponent();

        string conn ="consntring";

        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Colors", conn);

        DSColors dataSetcColors = new DSColors();

        adapter.Fill(dataSetcColors.Colors); 


        listBox1.DisplayMember = "ColorName";
        listBox1.ValueMember = "ColorID";
        listBox1.DataSource = dataSetcColors.Colors;
    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

知道如何在绑定 DataSource 时防止 listBox_SelectedIndexChanged 事件吗?

4

0 回答 0