• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

using WithEvents with control arrays

I would like to place a control array on a form and in my class which contains an instance of the form, i would like to receive the events from the control array.  Can this be done and if so, how?
  • 2
1 Solution
By using the RaiseEvent ## in your class, in one of the array events.
The raise event will send an event to the caller of the class.

emidiodAuthor Commented:

This works (not very elegant), but what i really would like is the following:

I have Form1 which has a control array of VB.CommandButtons which are Command1(0) and Command1(1).

I have a Class1 which has a module level variable with events declared as:
Private WithEvents m_oButton as VB.CommandButton

How do i set m_oButton to point to Command1 which is the control array so that i can use the following

Private Sub m_oButton_Click(Index as ingeger)

It seems to me that VB uses some hidden interface when dealing with control arrays and that i cannot use it the way i have outlined here.
>Can this be done and if so, how?
No, event parameters are not the same for control array. WithEvents does not include support for this 'Index' parameter.

Workaround: don't use control array
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now