Reference Form1 text box from AddinModule

Add-in Express™ Support Service
That's what is more important than anything else

Reference Form1 text box from AddinModule
 
Lance Friedemann




Posts: 24
Joined: 2017-02-10
I'm sure this is simple, but I'm trying to reference a textbox on Form1 from the AddinModule.vb code.

Dim sqCon As New SqlClient.SqlConnection(QCGMAIN)
Dim sqCmd As New SqlClient.SqlCommand

Dim Bol As Boolean = True
Dim dbStr As String = Nothing

'Read database
sqCmd.Connection = sqCon 'create the DB connection
sqCon.Open() 'open the connection
sqCmd.CommandText = "SELECT String1 FROM ADXOL WHERE Bit1 = '" & Bol & "'"
Dim sqReader As SqlDataReader = sqCmd.ExecuteReader() 'execute the SQL command
If sqReader.HasRows Then
While sqReader.Read()
If Not IsDBNull(sqReader.Item("String1")) Then
dbStr = sqReader.Item("String1").ToString
End If
End While
End If
sqReader.Close() 'always close the reader when you're done with it.
sqCon.Close()

ADXOlForm1_Ticket.TextBox1.Text = dbStr <--This doesn't work[QUOTE]


Does anyone know how to reference a Form1 Textbox1.Text from the AddinModule? I want to pass a string from AddinModule ADXNewInspector Event to the Form1 Textbox1.Text.
Posted 10 Feb, 2017 18:00:28 Top
Andrei Smolin


Add-in Express team


Posts: 14127
Joined: 2006-05-11
Lance,

Please check section Form Region Instancing, see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Feb, 2017 05:10:16 Top
Andrei Smolin


Add-in Express team


Posts: 14127
Joined: 2006-05-11
Lance,

I've decided to explain how an ADXOlForm is shown.

At the run time, the settings of an ADXOlFormCollectionItem that you specified at design time are used as follows. When you switch open an inspector window, the ADXOlFromsManager scans the Items collection and for each ADXOlFormCollectionItem it compares the settings and the actual properties of the inspector window. If they match, the forms manager creates an instance of the form you've specified and shows it.

That is, when you ask "how to reference a Form1 Textbox1.Text", you actually ask how to find the instance of that form and how to access the text of a Textbox control. On how to find the instance, check the section I mentioned above. On how to access the Texbox: after you get an instance, you should cast it to the type of your form - from ADXOlForm to ADXOlForm1. Then you can use the Textbox control is it accessible through the class interface (if required, make it Public or Friend).

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Feb, 2017 05:27:39 Top
Lance Friedemann




Posts: 24
Joined: 2017-02-10
Andrei,

Thank you for pointing me to the right documentation. I tried this code, but failed:



    Private Sub AdxOlFormsManager1_ADXNewInspector(inspectorObj As Object) Handles AdxOlFormsManager1.ADXNewInspector

        Dim thisForm As Form = AdxOlFormsCollectionItem1.GetCurrentForm
        MessageBox.Show("This form is " & thisForm.Name)

    End Sub

Posted 13 Feb, 2017 11:12:57 Top
Lance Friedemann




Posts: 24
Joined: 2017-02-10
Unfortunately, this is also producing False:



    Private Sub AdxOlFormsManager1_ADXNewInspector(inspectorObj As Object) Handles AdxOlFormsManager1.ADXNewInspector

        Dim form As ADXOlForm1_Ticket = TryCast(AdxOlFormsManager1.Items(0).GetCurrentForm(AddinExpress.OL.EmbeddedFormStates.Active), ADXOlForm1_Ticket)
        Dim bol As Boolean = False
        If form IsNot Nothing Then bol = True
        MessageBox.Show("Form found is " & bol.ToString)

    End Sub



Can you please provide the specific method code example for determining the instance of a form when it is created or activated??
Posted 13 Feb, 2017 13:03:05 Top
Andrei Smolin


Add-in Express team


Posts: 14127
Joined: 2006-05-11
Hello Lance,

I suggest that you do this in another way. Instead of getting the form in an event that may occur for all or some forms, intercept the ADXBeforeFormShow event, make sure AdxOlForm.InspectorObj is not Nothing, and set the text box on this form: Me.TextBox1.Text = "some text".

The difference is: an ADXOlForm is shown/hidden as a reaction to a change in Outlook windows, while an Outlook event occurs as a result of an inner logic of Outlook.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Feb, 2017 03:59:21 Top
Lance Friedemann




Posts: 24
Joined: 2017-02-10
This also fails. Please provide a small code snippet of the proper method and more importantly WHERE this code should reside. Does it belong in AddinModule.vb or in the ADXOLForm1.vb??

In AddinModule.vb:


Private Sub AdxOlFormsManager1_ADXBeforeFormInstanceCreate(sender As Object, args As AddinExpress.OL.BeforeFormInstanceCreateEventArgs) Handles AdxOlFormsManager1.ADXBeforeFormInstanceCreate

  If Not IsNothing(ADXForm1.InspectorObj) Then '<--ERROR! Object reference not set to an instance of an object.

     'do stuff

  End If

End Sub



I cannot find the ADXBeforeFormShow event in either the AddinModule.vb or the ADXOLForm1.vb. WHERE should this code reside to provide the instance of the form before it is created??

Please forgive my urgency, I have been fighting with this for a week and we need to move forward with our application.
Posted 14 Feb, 2017 23:35:14 Top
Andrei Smolin


Add-in Express team


Posts: 14127
Joined: 2006-05-11
Hello Lance,

ADXOlForm1:
    Private Sub ADXOlForm1_ADXBeforeFormShow() Handles MyBase.ADXBeforeFormShow
        Me.TextBox1.Text = MyAddin33.AddinModule.CurrentInstance.SomeValue
    End Sub


Add-in module:

    Public ReadOnly Property SomeValue() As String
        Get
            Return System.DateTime.Now.ToLongTimeString()
        End Get
    End Property


Example: http://temp.add-in-express.com/support/MyAddin33-OutlookForm.zip

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Feb, 2017 03:05:17 Top
Lance Friedemann




Posts: 24
Joined: 2017-02-10
Andrei,


Public ReadOnly Property SomeValue() As String 
    Get 
        Return System.DateTime.Now.ToLongTimeString() 
    End Get 
End Property 



How does System.DateTime.Now.ToLongTimeString() give me the current instance of the ADXOLForm from the AddinModule??
Posted 15 Feb, 2017 10:33:03 Top
Andrei Smolin


Add-in Express team


Posts: 14127
Joined: 2006-05-11
Hello Lance,

It doesn't. The operation is done from the form instance itself so you don't need to find the instance first. You need to replace the SomeValue call with a call that reads data from the DB. Alternatively, you can retrieve that info right in the code of the ADXOlForm.

If you need to check whether this instance is the instance required, you can use ADXOlForm.InspectObj (for an inspector form region) and/or ADXOlForm.ExplorerObj (for an explorer form region) properties.

This is what I suggested earlier:
Andrei Smolin writes:
I suggest that you do this in another way. Instead of getting the form in an event that may occur for all or some forms, intercept the ADXBeforeFormShow event, make sure AdxOlForm.InspectorObj is not Nothing, and set the text box on this form: Me.TextBox1.Text = "some text".


Hope this helps.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Feb, 2017 03:14:40 Top