绑定DataSource时如何防止listBox_SelectedIndexChanged事件?

时间:2013-01-05 19:38:39

标签: c# winforms listbox

我有ListBox控件(WinForm项目)。

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

以下是代码:

public 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事件吗?

0 个答案:

没有答案