Switch Views and Set Focus together - InfoPath Dev
in

InfoPath Dev

Switch Views and Set Focus together

Last post 07-09-2012 05:44 PM by Gennady Vanin (Геннадий Ванин, Новосибирск). 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 07-05-2012 12:52 PM

    • alexj
    • Not Ranked
    • Joined on 07-05-2012
    • Posts 18

    Switch Views and Set Focus together

    Hello, I am a very bright green InfoPath user.   What I would like is to be able to do two things at once when a user clicks a button.

    1.  Switch to a different view

    2.  Set focus to one of the controls on that view

    I can get a button to switch views easily

    Public Sub CTRL1_14_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ViewInfos.SwitchView("SF182")

    End Sub

    And after much frustration managed to get clicking a button to set focus on a control on the same view

    Public Sub CTRL78_7_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
    Dim textNode As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tSF182/@EducLevel", NamespaceManager)

    CurrentView.SelectText(textNode)

    End Sub

    Getting these two things to happen at the same time results in errors from the attempt 

    System.Runtime.InteropServices.COMException
    The specified values for the View.SelectText call are not valid.
       at Microsoft.Office.Interop.InfoPath.SemiTrust.View.SelectText(IXMLDOMNode pxnField, Object varViewContext)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.SelectText(IXMLDOMNode pxnField, Object varViewContext)
       at Microsoft.Office.InfoPath.Internal.ViewHost.SelectText(XPathNavigator xmlNode)
       at ipfSF182a.FormCode.CTRL1_14_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    Any ideas how I can make this work?

  • 07-06-2012 09:29 AM In reply to

    • alexj
    • Not Ranked
    • Joined on 07-05-2012
    • Posts 18

    Re: Switch Views and Set Focus together

    Still having no luck at this.  I tried putting a new subroutine to hold the set focus, but that did not work

     Public Sub CTRL1_14_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ViewInfos.SwitchView("SF182")

    mynewsub()

    End Sub

    Public Sub mynewsub()
    Dim textNode As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tSF182/@EducLevel", NamespaceManager)

    CurrentView.SelectText(textNode)

    End Sub

    My new improved error from doing this is

    System.Runtime.InteropServices.COMException
    The specified values for the View.SelectText call are not valid.
       at Microsoft.Office.Interop.InfoPath.SemiTrust.View.SelectText(IXMLDOMNode pxnField, Object varViewContext)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.SelectText(IXMLDOMNode pxnField, Object varViewContext)
       at Microsoft.Office.InfoPath.Internal.ViewHost.SelectText(XPathNavigator xmlNode)
       at ipfSF182a.FormCode.mynewsub()
       at ipfSF182a.FormCode.CTRL1_14_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     

    My goal is to set it up where users who are filling out the form can click a button taking them to a new view which is help specific to the question they are currently on (in this case Education level), then on that view they click a button which takes them back to the main (SF182) view and ideally takes them back to the relevant field to fill out

     

  • 07-07-2012 01:25 AM In reply to

    Re: Switch Views and Set Focus together

     I've just reproduced it

    Tried to find a workaround, for example through "outsourcing" part of code of switching views through rules instead of through custom code and this also did not work.

    To me it looks like a bug, gonna ask in msdn forum and post here a link

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
  • 07-09-2012 07:23 AM In reply to

    • alexj
    • Not Ranked
    • Joined on 07-05-2012
    • Posts 18

    Re: Switch Views and Set Focus together

    Thank you, at least I know I'm not just going mad

     I've continued poking at it off and on with no real progress, and it has been getting somewhat vexing

  • 07-09-2012 10:52 AM In reply to

    Re: Switch Views and Set Focus together

     Now I am going mad because the answer told that this happens only in browser based forms while I am having it without going outside of my computer in preview!

    Ans now I wanna know what is wrong with my machine!

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
  • 07-09-2012 11:00 AM In reply to

    • alexj
    • Not Ranked
    • Joined on 07-05-2012
    • Posts 18

    Re: Switch Views and Set Focus together

    I am also doing it on my computer in Preview, though I am using Infopath 2007 - I am not trying to use browser form (everyone who will use the form will have Infopath 2007 on their computer already)

     I will try to use the answer, it looks cool 

     

  • 07-09-2012 11:35 AM In reply to

    • alexj
    • Not Ranked
    • Joined on 07-05-2012
    • Posts 18

    Re: Switch Views and Set Focus together

    I have tried to follow the answer, but, I am getting nothing to happen as far as selecting the text box is concerned (there is no error box or anything, but it also doesn't select the text box or do anything I can perceive) other than switch view

     It is because the View Switched event is not triggering somehow I think

     I tried this and the button clicked message box appeared, but the others did not

     

    Public Sub FormEvents_ViewSwitched(ByVal sender As Object, ByVal e As ViewSwitchedEventArgs)

    MessageBox.Show("My FormEvents_ViewSwitched sub was reached")

    If CurrentView.ViewInfo.Name = "SF182" Then

    Dim textNode As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:tSF182/@EducLevel", NamespaceManager)
    MessageBox.Show("My If Statement was reached")

    CurrentView.SelectText(textNode)

    End If

    End Sub

    Public Sub CTRL1_14_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    MessageBox.Show("Button was clicked")

    ViewInfos.SwitchView("SF182")

    End Sub

     The final end sub is there, but I cannot get it to go blue.  It is blue in InfoPath but I couldn't get it to copy paste

     

  • 07-09-2012 05:44 PM In reply to

    Re: Switch Views and Set Focus together

    That answer does tell how to make it work through switching by choosing/switching a view on ribbon using its "Current Vuew:" drop-down list there (and selecting text by catching that even) only but not through button click on Infopath form which still produces the same error

     You should have also generated

    • Public Sub FormEvents_ViewSwitched ( ByVal sender As Object, ByVal e As ViewSwitchedEventArgs)

     by clicking "View Switched Event" button on ribbon in order to generate its binding to FormEvents_ViewSwitched method inmethod

    • Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup 'in VB.NET
      or
      public void InternalStartup() //in C#

     

     which is:

    • AddHandler EventManager.FormEvents.ViewSwitched, AddressOf FormEvents_ViewSwitched  'in VB.NET (in VisualBasic.NET)
      or
      EventManager.FormEvents.ViewSwitched += new ViewSwitchedEventHandler(FormEvents_ViewSwitched); (in C#)


     For me this works. I checked it in C# and then rechecked in VB.NET

     Though this is flogging the dead horse

     

    Gennady Vanin (Novosibirsk) --- Геннадий Ванин (Новосибирск)
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.