[dba-VS] Using RemoveHandler in a Combobox Base Class

Dan Waters df.waters at outlook.com
Fri Jun 5 11:52:06 CDT 2015


Hi Charlotte,

This is the whole story.  I have a custom control named PSICombobox which
inherits from ComboBox.  

Below is shown one of the several events I've written for the PSICombobox,
which could be used hundreds of places on many different WinForms.

The issue is that when the Me.DroppedDown method is executed, the combobox's
SelectedIndexChanged event on the form is automatically run, which of course
can cause a problem.  I want to prevent the combobox's SelectedIndexEvent
(on the form) from being run every time it is dropped down from the code in
this custom control's class.

Typically I would do this in the form's code using RemoveHandler.  But that
requires knowing the address of the combobox, which is readily available by
the form's code.  But how would I get that address in the custom control's
class code?

Or, is there another way to do this without using RemoveHandler?

Thanks!
Dan

'--------------------------------------------------
Public Class PSICombobox

    Inherits ComboBox
    Protected Overrides Sub OnEnter(e As EventArgs)

        If Me.Enabled = False Then Exit Sub

        Me.BackColor = System.Drawing.Color.FromArgb(255, 255, 160)	 '--
Pale Yellow

        stgComboboxTextEnter = Me.Text

        If Me.SelectedIndex = -1 Then

            RemoveHandler Me.SelectedIndexChanged, AddressOf [WHAT GOES
HERE?]

            '-- For user convenience drop down the combobox when it gets the
focus and it's empty
            Me.DroppedDown = True

            RemoveHandler Me.SelectedIndexChanged, AddressOf [WHAT GOES
HERE?]

        End If

        MyBase.OnEnter(e)

    End Sub
End Class
'--------------------------------------------------

-----Original Message-----
From: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] On Behalf Of
Charlotte Foust
Sent: Thursday, June 04, 2015 11:55 PM
To: Development in Visual Studio
Subject: Re: [dba-VS] Using RemoveHandler in a Combobox Base Class

What I meant was test for a condition in that  SelectedIndexChanged event
and then either cancel the event or handle it normally.  Is there a
condition you could test for in that event so you would know whether to
allow it to continue?

Charlotte Foust
(916) 206-4336

On Wed, Jun 3, 2015 at 2:00 PM, Dan Waters <df.waters at outlook.com> wrote:

> Hi Charlotte,
>
> I will add the handler back in a few lines of code down.
>
> What do you mean 'branching the code'?
>
> Dan
>
> -----Original Message-----
> From: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] On Behalf Of 
> Charlotte Foust
> Sent: Wednesday, June 03, 2015 3:40 PM
> To: Development in Visual Studio
> Subject: Re: [dba-VS] Using RemoveHandler in a Combobox Base Class
>
> Why remove the handler rather than branching the code in it?
>
> Charlotte Foust
> (916) 206-4336
>
> On Wed, Jun 3, 2015 at 8:09 AM, Dan Waters <df.waters at outlook.com> wrote:
>
> > I have a combobox base class (a custom control) which will cause the 
> > combobox to drop down when the control is entered and the 
> > selectedindex =
> > -1
> > (it's empty).  This is a convenience for users.
> >
> >
> >
> > However, I recently discovered that when the combobox is dropped 
> > down, its SelectedIndexChanged event also fires, which I want to 
> > prevent. In the code behind the form, I can just use
> >
> >
> >
> > RemoveHandler cboName.SelectedIndexChanged, AddressOf 
> > cboName_SelectedIndexChanged
> >
> >
> >
> > But in the base class, I don't know how to specify what the address 
> > is for the combobox on the form.
> >
> >
> >
> > This is where I'm stuck:
> >
> > RemoveHandler, Me.SelectedIndexChanged, AddressOf [What is the 
> > address?]
> >
> >
> >
> > How can this be done?
> >
> >
> >
> > Thanks!
> >
> > Dan
> >
> >
> >
> > _______________________________________________
> > dba-VS mailing list
> > dba-VS at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/dba-vs
> > http://www.databaseadvisors.com
> >
> _______________________________________________
> dba-VS mailing list
> dba-VS at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vs
> http://www.databaseadvisors.com
>
> _______________________________________________
> dba-VS mailing list
> dba-VS at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vs
> http://www.databaseadvisors.com
>
_______________________________________________
dba-VS mailing list
dba-VS at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vs
http://www.databaseadvisors.com



More information about the dba-VS mailing list