Witam,
W zdarzeniu comboBox1_SelectedIndexChanged chcę odczytać aktualną wartość i dać do zapytania Select...
Niestety podczas uruchamiania programu dwukrotnie pojawia się wartość: [1, Sunday].
Jak się tego pozbyć?
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<int, string> comboSource = new Dictionary<int, string>();
comboSource.Add(1, "Sunday");
comboSource.Add(2, "Monday");
comboSource.Add(3, "Tuesday");
comboSource.Add(4, "Wednesday");
comboSource.Add(5, "Thursday");
comboSource.Add(6, "Friday");
comboSource.Add(7, "Saturday");
comboBox1.DataSource = new BindingSource(comboSource, null);
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(Convert.ToString(comboBox1.SelectedValue));
// tu jest ok
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(Convert.ToString(comboBox1.SelectedValue));
// tu chcę wykorzystać SelectedValue do tworzenia zapytania Select w bazie danych
// ale dwokrotnie mam: [1, Sunday]
}
Dziękuję za pomoc