Uncharted Territory-VBForums
Results 1 to 5 of 5

Thread: Uncharted Territory

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2017
    Posts
    238

    Uncharted Territory

    I have a VSTA (Visual Studio For Applications) InfoPath project that leaves much to the imagination. There is limited help on the we for what I am trying to invent.

    I've tried many long winded approaches at creating WinForm dynamically, and have had various issues with disposing and duplicating the form and all it's controls.

    Now I have created a Form Class that is behaving much better as far as disposal and I can keep the methods tidy in it's own class instead of within the same FormCode class which is created by VSTA.

    This will also allow me to just copy this class into any InfoPath solution with less effort.

    Now I am having problems trying to pass values from the Form Class to the FormCode Class members, mostly because I have no idea as to how this class is interacting with the InfoPath form itself.

    Here is an example of how you set a string on the Infopath Form
    Code:
            Public Sub SetPerson()
                Me.CreateNavigator.SelectSingleNode("/my:ROOT/my:Init/my:InitEmpID", Me.NamespaceManager).SetValue("1234")
            End Sub
    When I add the 'shared' keyword like so...
    Code:
        Public Shared Sub SetPerson()
                Me.CreateNavigator.SelectSingleNode("/my:ROOT/my:Init/my:InitEmpID", Me.NamespaceManager).SetValue("Some Value")
            End Sub
    I get
    'Me' is valid only within an instance method
    So I comment that out and create a variable for testing...
    Code:
           Public Shared Sub SetPerson(ByVal EmpID As String)
    
                Dim EmployeeID As String = EmpID
    
                'Me.CreateNavigator.SelectSingleNode("/my:ROOT/my:Init/my:InitEmpID", Me.NamespaceManager).SetValue("Some Value")
            End Sub
    And pass the string from the winform successfully...
    Code:
    Imports Microsoft.Office.InfoPath
    Imports System.Windows.Forms
    Imports mshtml
    Imports System
    Imports System.Xml
    Imports System.Xml.XPath
    Imports System.Data
    Imports System.Data.SqlClient
    Imports PurchReq
    
    Public Class FrmFindPeople
        Dim DGV_People As New DataGridView With {.Dock = DockStyle.Fill, .RowHeadersVisible = False, .AllowUserToAddRows = False, .AllowUserToDeleteRows = False,
                                                        .AutoGenerateColumns = True}
        Dim TB_PeopleSearch As New TextBox With {.Name = "TBSearch", .ForeColor = Drawing.Color.Gray, .Text = "Search...", .Width = 200, .Dock = DockStyle.Left}
        Dim HeadPanel As New Panel With {.Dock = DockStyle.Top, .Height = 30, .Padding = New Padding(10)}
        Dim BodyPanel As New Panel With {.Dock = DockStyle.Fill, .Padding = New Padding(10)}
        Dim FootPanel As New Panel With {.Dock = DockStyle.Bottom, .Height = 30}
    
    
        Private Sub FrmFindPeople_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With HeadPanel
                .Controls.Add(TB_PeopleSearch)
            End With
    
            With BodyPanel
                .Controls.Add(DGV_People)
            End With
    
            With Me
                .Controls.Add(HeadPanel)
                .Controls.SetChildIndex(HeadPanel, 1)
    
                .Controls.Add(BodyPanel)
                .Controls.SetChildIndex(BodyPanel, 0)
    
                .Controls.Add(FootPanel)
                .Controls.SetChildIndex(FootPanel, 2)
            End With
    
            PurchReq.FormCode.SetPerson("1234") '<---
    
        End Sub
    
    End Class
    I cant for the life of me get this string to the actual InfoPath form. I am real close... maybe someone has an idea I could try.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,513

    Re: Uncharted Territory

    I don't have InfoPath experience, but it seems that a NamespaceManager is important... can you set a variable within FrmFindPeople_Load to equal Me.NamespaceManager?

    If so you could pass that as a parameter to SetPerson.

    Similar applies to Me.CreateNavigator.


    By the way, what is your reason for wanting to have the routine Shared rather than instance specific?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2017
    Posts
    238

    Re: Uncharted Territory

    can you set a variable within FrmFindPeople_Load to equal Me.NamespaceManager?
    "Me" in that sense, I believe, would refer to the FrmFindPeople Class and not the FormCode Class which is where all the InfoPathy things are happening.
    By the way, what is your reason for wanting to have the routine Shared rather than instance specific?
    Honestly it doesnt matter to me one bit how this value is passed. Right now it is similar to passing a kidney stone!
    I am trying to get a better handle on how the XPathNavigator works, its all very confusing.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,513

    Re: Uncharted Territory

    That didn't actually answer either of my questions, but it sounds like having it Shared is the opposite of what you want, so remove Shared.

    If you get an error while trying to call it, create an instance variable to use, eg:
    Code:
                .Controls.SetChildIndex(FootPanel, 2)
            End With
    
            Dim formCode as New PurchReq.FormCode
            formCode.SetPerson("1234")

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2017
    Posts
    238

    Re: Uncharted Territory

    I actually have tried that, which produces this
    Argument not specified for parameter 'initArgs' of 'Public Sub New(initArgs As System.AddIn.Contract.Collections.IRemoteArgumentArrayContract)'
    I have not got as far as to read about what param it is looking for and why.
    Last edited by kpmc; Dec 22nd, 2017 at 03:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.