Konstantin Mokhov
Konstantin Mokhov

Reputation: 672

cannot find where event is being raised from

I Create a function NewLoad() and call it in butto1_click. And i have event listBox1_SelectedIndexChanged which called itself during operation function "NewLoad"

private void button1_Click(object sender, EventArgs e)
{
    NewLoad();
}

private void NewLoad()
{
    String text = textBox1.Text.Trim();
    textBox1.Text = text;
    oleDbSelectCommand1.Parameters[0].Value = text;

    dataSet11.Clear(); <<<--- call listbox1_SelectedIndexChanged

    oleDbDataAdapter1.Fill(dataSet11);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    dataSet21.Clear();
}

why this happens and how i can to avoid it?

Upvotes: 0

Views: 45

Answers (2)

TheBlindSpring
TheBlindSpring

Reputation: 631

If you have something selected in list box 1, when you clear it, the selected index will change, thus raising selection changed event.

Upvotes: 0

SLaks
SLaks

Reputation: 887449

My psychic debugging skills tell me that the listbox is databound to the dataset.

When you clear your dataset, the listbox is emptied, and the selection changes. This raises the relevant event.

Upvotes: 3

Related Questions