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