Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

Custom Control Events... GotFocus and LostFocus not firing.

Hi All,

I'm currently trying to get a custom controls events to fire but for some reason they won't. I'm programmatically adding two custom controls (made by my company's controls group) to a Form.  I declared the control as follows...

    Private WithEvents RCNWMGC As WealthPoint.CoreControls.Controls.RegularControl

and then I selected the gotfocus and lostfocus events and added code...

    Private Sub RCNWMGC_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles RCNWMGC.GotFocus
       Dim tmpI As Integer
        tmpI = Integer.Parse(RCNWMGC.Text.Substring(1, RCNWMGC.Text.Length - 1))
        RCNWMGC.Text = tmpI.ToString("C")
    End Sub

    Private Sub RCNWMGC_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles RCNWMGC.LostFocus
        RCNWMGC.Text = CType(RCNWMGC.Text, Integer).ToString("C")
    End Sub

When I ran the program the events did not fire. I then removed the "Handles..." text and added these two statements to the startup routine...

        AddHandler Me.RCNWMGC.GotFocus, AddressOf RCNWMGC_GotFocus
        AddHandler Me.RCNWMGC.LostFocus, AddressOf RCNWMGC_LostFocus

The above statements did not cause the events to fire either. Anyone have any idea why GotFocus and lostFocus aren't firing?

Thanks in advance for your help.

Mike

0
mgorgone
Asked:
mgorgone
  • 3
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> I'm programmatically adding two custom controls (made by my company's controls group) to a Form.

Where is your code that creates an instance of WealthPoint.CoreControls.Controls.RegularControl and adds it to your forms control collection?
0
 
mgorgoneAuthor Commented:
The calls to create the control (and a bunch of others) is in a subroutien named CreateChildControls which is called in the New constructor of another custom control which is created when the form is loaded. Does that help?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I just wanted to make sure that you were assigning the newly created control to your already declared RCNWMGC variable.

Something like...

    RCNWMGC = New WealthPoint.CoreControls.Controls.RegularControl
    RCNWMGC.Size = ...
    RCNWMGC.Location = ...
    Me.Controls.Add(RCNWMGC)

If you are doing this correctly and it doesn't work then it is possible that the WealthPoint.CoreControls.Controls.RegularControl doesn't properly expose these events.  It will have them because of Inheritance but the authors may not have coded the control so that these events ever fire.

Do you have any existing apps that correctly use this control with the GotFocus() and LostFocus() events?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mgorgoneAuthor Commented:
The code is performing the steps you mention below...

RCNWMGC = New WealthPoint.CoreControls.Controls.RegularControl
    RCNWMGC.Size = ...
    RCNWMGC.Location = ...
    Me.Controls.Add(RCNWMGC)

and I'm with you on trying to find some other place in the project that tries to handle those events. If I find them I'll update what's going on.

Thanks
0
 
Bob LearnedCommented:
There is always the Control.CanFocus property.

Bob
0
 
mgorgoneAuthor Commented:
Eureaka,

After looking a little bit more I found the "DataControl" property which is the textbox portion of the overall control. I changed the AddHandler to this and now the event is firing.

Before...
AddHandler Me.RCNWMGC.GotFocus, AddressOf RCNWMGC_GotFocus
AddHandler Me.RCNWMGC.LostFocus, AddressOf RCNWMGC_LostFocus

Now...
AddHandler Me.RCNWMGC.DataControl.GotFocus, AddressOf RCNWMGC_GotFocus
AddHandler Me.RCNWMGC.DataControl.LostFocus, AddressOf RCNWMGC_LostFocus

Thanks to all who responded with help.

Mike
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Like I said earlier, "the authors may not have coded the control so that these events ever fire."

The control authors should have daisy-chained the events so that when the DataControl got the focus it fired the GotFocus() event for the ENTIRE control.

~IM
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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