Identifying a control by its handler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Magnus.Moraberg@gmail.com

    #1

    Identifying a control by its handler

    Hi,

    I have a number of binding navigator controls on my form. I add "plus"
    buttons (buttons used to add a new row to the relevant datagirdview)
    to them as follows -

    bindingNavigato r.AddNewItem.En abled = false;

    this.bindingNav igator.Items.Ad dRange(new
    System.Windows. Forms.ToolStrip Item[]
    {
    ...
    this.bindingNav igatorAddNewIte m,
    ...
    });

    Each Binding Navigator has a "plus" toolStripButton which I add an
    event to as follows -

    this.bindingNav igatorAddNewIte m.Click += new
    System.EventHan dler(this.AddRo wToDataGridView );

    All the plus buttons have the exact same handler -
    this.AddRowToDa taGridView.

    I was wondering if it would be possible to loop through my
    BindingNavigato rs and identify those toolStripButton s that have
    this.AddRowToDa taGridView as a handler. By doing so, I can identify
    all "plus" buttons and set these buttons as disabled or enabled as I
    so desire.

    Thanks,

    Barry
  • Magnus.Moraberg@gmail.com

    #2
    Re: Identifying a control by its handler

    On 21 Okt, 11:09, Magnus.Morab... @gmail.com wrote:
    Hi,
    >
    I have a number of binding navigator controls on my form. I add "plus"
    buttons (buttons used to add a new row to the relevant datagirdview)
    to them as follows -
    >
    bindingNavigato r.AddNewItem.En abled = false;
    >
    this.bindingNav igator.Items.Ad dRange(new
    System.Windows. Forms.ToolStrip Item[]
    {
                ...
                this.bindingNav igatorAddNewIte m,
                ...
    >
    });
    >
    Each Binding Navigator has a "plus" toolStripButton which I add an
    event to as follows -
    >
    this.bindingNav igatorAddNewIte m.Click += new
    System.EventHan dler(this.AddRo wToDataGridView );
    >
    All the plus buttons have the exact same handler -
    this.AddRowToDa taGridView.
    >
    I was wondering if it would be possible to loop through my
    BindingNavigato rs and identify those toolStripButton s that have
    this.AddRowToDa taGridView as a handler. By doing so, I can identify
    all "plus" buttons and set these buttons as disabled or enabled as I
    so desire.
    >
    Thanks,
    >
    Barry
    I could derive my own AddRowToDataGri dViewButton class from
    toolStripButton and use GetType() to identify it... What do you think?

    Comment

    • Magnus.Moraberg@gmail.com

      #3
      Re: Identifying a control by its handler

      On 21 Okt, 11:30, Magnus.Morab... @gmail.com wrote:
      On 21 Okt, 11:09, Magnus.Morab... @gmail.com wrote:
      >
      >
      >
      Hi,
      >
      I have a number of binding navigator controls on my form. I add "plus"
      buttons (buttons used to add a new row to the relevant datagirdview)
      to them as follows -
      >
      bindingNavigato r.AddNewItem.En abled = false;
      >
      this.bindingNav igator.Items.Ad dRange(new
      System.Windows. Forms.ToolStrip Item[]
      {
                  ...
                  this.bindingNav igatorAddNewIte m,
                  ...
      >
      });
      >
      Each Binding Navigator has a "plus" toolStripButton which I add an
      event to as follows -
      >
      this.bindingNav igatorAddNewIte m.Click += new
      System.EventHan dler(this.AddRo wToDataGridView );
      >
      All the plus buttons have the exact same handler -
      this.AddRowToDa taGridView.
      >
      I was wondering if it would be possible to loop through my
      BindingNavigato rs and identify those toolStripButton s that have
      this.AddRowToDa taGridView as a handler. By doing so, I can identify
      all "plus" buttons and set these buttons as disabled or enabled as I
      so desire.
      >
      Thanks,
      >
      Barry
      >
      I could derive my own AddRowToDataGri dViewButton class from
      toolStripButton and use GetType() to identify it... What do you think?
      No, I can't do that since I would need to create a user control to
      which I can't add a ToolStipButton. I'm using VC2005 and its form
      designer. Any suggestions?

      Comment

      • Peter Duniho

        #4
        Re: Identifying a control by its handler

        On Tue, 21 Oct 2008 02:09:01 -0700, <Magnus.Moraber g@gmail.comwrot e:
        [...]
        All the plus buttons have the exact same handler -
        this.AddRowToDa taGridView.
        >
        I was wondering if it would be possible to loop through my
        BindingNavigato rs and identify those toolStripButton s that have
        this.AddRowToDa taGridView as a handler. By doing so, I can identify
        all "plus" buttons and set these buttons as disabled or enabled as I
        so desire.
        I don't see why your subclass idea wouldn't work (your third message
        doesn't explain why very well). However, it seems to me that the most
        straight-forward solution is probably the best: just keep a list of all
        the "plus" buttons (in an array, or a List<T>, for example). You can even
        use the same list to manage the event handler subscription if you like.
        Just make a helper method that subscribes your AddRowToDataGri dView method
        to the event and adds the "bindingNavigat ion..." instance to your list as
        it does so.

        Pete

        Comment

        Working...