0

I have a comboBox that registers to ComboBox_SelectedIndexChanged event. When that event is completed I want to do another change.

I tried to registered to Combo_SelectionChangeCommitted event but that event occures before the ComboBox_SelectedIndexChanged

Does anyone know what event occurs after the ComboBox_SelectedIndexChanged is completed?

    private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
      int selectedIndex = ((ComboBox)sender).SelectedIndex;
      Update(selectedIndex);
      ActiveNextRow(); // I want that method will occurred after the selectedIndexChanged event end.
    }

Thanks

Yoav
  • 150
  • 3
  • 9
  • What other change do you need to do? Can it not be done as part of the SelectedIndexChanged event? – sr28 Jan 04 '16 at 13:30
  • I need to active another control, I already try to do it, the result is the comboBox selection is not displayed. – Yoav Jan 04 '16 at 13:33
  • Can you show some code of what you're trying to do? – sr28 Jan 04 '16 at 13:36
  • Can you explain more generally what it is you're trying to do? It looks like when the user selects a different item in the combo box you 'update' the item and then try and do 'ActiveNextRow' whatever that is. – sr28 Jan 04 '16 at 14:22
  • After ComboBox_SelectedIndexChanged() occurred I have to update the parent object , this update include a calculation that take time, therefore the selectedIndexChanged event isn't complete and I change the focus other object , therefore the I need to register to the event that raised when the ComboBox_SelectedIndexChanged finish. – Yoav Jan 04 '16 at 14:33
  • I'm still not clear. Are you saying that when SelectedIndexChanged event is fired you update the parent object, which kicks off a long running calculation. After this has finished you then change the focus to another object, which is done by ActiveNextRow()? – sr28 Jan 04 '16 at 15:03

1 Answers1

0

This question can be generalized to the order of events: link

As an example you can do the following:

    private void Form1_Load(object sender, EventArgs e)
    {
        comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
        comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged3;
        comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged2;
    }
    private void comboBox1_SelectedIndexChanged3(object sender, EventArgs e)
    {
        // Your code here
    }
    private void comboBox1_SelectedIndexChanged2(object sender, EventArgs e)
    {
        // Your code here
    }
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Your code here
    }

The execution order will be exactly as prescribed in the Form1_Load method. Another way to achieve what you want would be to put the call to your method at the end of the comboBox1_SelectedIndexChanged method (in the same thread).

If your Update method runs some process on a separate thread, the comboBox1_SelectedIndexChanged method will be completed before that process run by Update completes.

Community
  • 1
  • 1
Almis
  • 171
  • 1
  • 2
  • 11