I have a form with among other things a cancel button. However, I also have a combobox which the form sets a the start point when the form is opened.
The thing is, when I open the form its starting in the combobox (as part of the user control) and I have the combobox set so if you leave it without selecting an option it throws up a messageBox. The sub is presented below..
My Problem: If I open the form and then click on the cancel button (to immediately close the form) it leaves the combobox first and since there is nothing selected it throws up the messageBox. It should instead close the form.
I have tried to set the button click event but it doesnt fire before the leave for the combobox event.
How do I detect the user is clicking on the cancel button and in this instance, ignore the fact there is nothing in the combobox and go straight on and close the form??
Private Sub USCClientList_LEAVE() Implements creditorInvoiceINTERFACE.IfrmCreditorInvoice.USCClientList_LEAVE
If thisUserControl.btnSearch.Focused Then
If thisUserControl.cmbxClientName.SelectedIndex = -1 Then
Dim reply = MessageBoxEx.Show("You must select a valid client from the dropdown list...", "Selection Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error, _
lblInvoiceDate.Enabled = True
dtInvoiceDate.Enabled = True
Catch ex As Exception
manageWindowsViewError("creditorTASK", "frmCreditorInvoice", "USCClientList_LEAVE", ex)