views:

739

answers:

2

I have a ContextMenu that is displayed after a user right clicks on a ComboBox. When the user selects an item in the context menu, a form is brought up using the ShowDialog() method.

    If frmOptions.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
        LoadComboBoxes()
    End If

When that form is closed, I refresh all the data in the ComboBoxes on the parent form. However, when this happens the ComboBox that opened the ContextMenu is reset to have a selected index of -1 but the other selected indexes of the other ComboBoxes remain the same.

How do I prevent the ComboBox that opened the context menu from being reset?

+1  A: 

One way to handle this would be to use the context menu's Popup event to grab the selected index of the combobox launching the menu. When the dialog form closes reset the selected index.

DaveK
A: 

I figured it out.

I created a method that passed the ContextMenu.SourceControl() property by reference so I could manipulate the control that called the ContextMenu. In the beginning of the method, I got the SelectedValue of the ComboBox and the reloaded the data in the ComboBoxes. I then set the SelectedValue to the value I had got in the beginning of the method.

Thank you DaveK for pointing me in the right direction.

Bryan Roth