Showing results for 
Search instead for 
Do you mean 

Limiting code execution on custom tab.

Copper Contributor
Posts: 153
Country: Belgium

Limiting code execution on custom tab.



Basically I'm making a custom tab on which I'm showing info on a contact taken from our ERP/Bookkeeping software.

What I'm trying to do however, is limit when the code on the custom tab gets executed. For example I don't want the plug-in to start querying the ERP database every time someone goes to another contact, this would be horribly inefficient and a complete waste of resources. I want this to only happen when the user is on the custom tab I added.


I first thought, seeing as I'm adding a custom control to a tabpage, which I'm adding to the Act Lay-out, I'd be able to call Me.Parent in the custom control to get what should be the TabPage, and from that TabPage call Parent again to get the TabControl.


But apparantly that doesn't seem to be working.


Basically I need some way of catching a TabIndex changed event from the TabControl, and checking if the current TabPage is my custom Tab.


Is there a way to do this in the Act SDK?

Bronze Super Contributor
Posts: 1,284
Country: USA

Re: Limiting code execution on custom tab.

Why not check the me.visible property?


Please excuse this completley untested code since its from memory. I am in New Jersey ans still without power due to hurricane Sandy. My primary dev PC is dark but I have a laptop and a hot spot! 


Public Class usrMyTab
    Inherits System.Windows.Forms.UserControl

 ' Create our internal handler
 Dim RefreshMyTabEventHandler As New EventHandler(AddressOf RefreshMyTab)

     ' Attach to the ACT SDK event
 Public sub new(ByVal HostApplication As Act.UI.ActApplication)
      AddHandler HostApplication.CurrentContactChanged, RefreshMyTabEventHandler)
 End Sub

    ' Listening to ACT's events

 Private Sub RefreshMyTab()
  ' Are we on the COntact Detial view?
    If Me.HostApplication.CurrentViewName = ACTUIToolkit.ACTViews.ContactDetailViewName  Then
  ' If YES then call the visibnle change event
  ' which will refresh the control
       Me.usrViewGeneric_VisibleChanged(Me, Nothing)
    End If
 End SUb

     Private Sub usrMyTab_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
    ' Only refresh if we are visible, When ACT raised the contact chnage event
    ' we may not be visible cuase the user has focus on another tab
            If (Me.Visible = True) Then
                ' Your Refresh Code here!
            End If
 End Sub

End Class


Hope this helps

-- Jim Durkin

Copper Contributor
Posts: 153
Country: Belgium

Re: Limiting code execution on custom tab.

Never thought it'd be as simple as the visible property. Didn't expect the visible property to be set to false for a single tab when the user goes to another tab.


Many thanks.