11 Replies Latest reply on Jul 24, 2014 4:14 PM by scoxey

    Passing the Element of Interest to a new screen

    tgreen

      Is there a way to pass the "element of interest" that's selected when changing screens so that the new screen that appears has the same "element of interest" selected?  this would be within the same piw file.  I want to make it so that the user doesn't have to go select the element again.  Saves confusion when flipping back and forth on screens that have to do with the same element types.  Thanks!

        • Re: Passing the Element of Interest to a new screen
          Marcos Vainer Loeff

          Hi Trevor,

           

          Here is what you have to do to achieve your goals:

          • Open the new display called "NewDisplay". The first display will be called "OldDisplay".
          • Copy the current context of the "OldDisplay" to the "NewDisplay"
          • Close the "OldDisplay".

          Please refer to the code snippet below:

           

           

           
               Dim NewDisplay As Display
                  Dim OldContextPath As String
                   Dim AFContext As ContextHandler
               Set OldDisplay = ThisDisplay
                   Set AFContext = Application.ContextHandlers("E")
                   OldContextPath = AFContext.CurrentContext(ThisDisplay)
               Set NewDisplay = Application.Displays.Open(NewDisplayPath, True)
                  Application.ContextHandlers("E").CurrentContext(NewDisplay) = OldContextPath
                  OldDisplay.Close (False)
          

           

           

          Let me know if you can apply this feature in your displays.

              • Re: Passing the Element of Interest to a new screen
                scoxey

                I can't seem to make this work!  Help!

                  • Re: Passing the Element of Interest to a new screen

                    Hello Scott,

                     

                    Please share some details about what you are doing and what's not working for you.

                      • Re: Passing the Element of Interest to a new screen
                        scoxey

                        Hi Gregor,

                         

                        All it seems to do when doing this is still open the element at the top of the tree in the new display.  I am essentially trying to open a detail display from an overview display with an element selected- and have that element be the one selected in the detail display.  Does that help?

                         

                        Thanks,

                         

                        Scott

                          • Re: Passing the Element of Interest to a new screen

                            Hello Scott,

                             

                            To my understanding this should work. So let's see if we can figure out why it's not working for you.

                            1. What's the name and path of the overview display?
                            2. What's the name and path of the detail display?
                            3. What display has the VBA code and what event are you using?
                            4. Can you please post your complete method or attach the display with your code?

                            Because I don't know if you are aware how to paste in code snippets or to attach a file, please allow me explaining how it works. Please select "USE RICH FORMATTING". This will show the editor with enhanced options. The button on the right hand side of the smile button, brings up the dialog allowing you to paste in code. Please select "VB" language. At the top of the editor you will find 3 tabs. The "Compose" tab will be active and "Options" and "Preview" are available. With "Options" you have the ability to attach a file to your post. 

                              • Re: Passing the Element of Interest to a new screen
                                scoxey

                                Hi Gregor- and thank you!

                                 

                                So, to simplify things the overview display is called "number 1".  The detail display it calls is called "number 2".  The paths are C:\documents.  "number 1" has the vba code.  

                                 

                                I have tried the button click event and it didn't seem to work.  I have added a rectangle in and put it there.  

                                 

                                 

                                 

                                 

                                 
                                Private Sub Rectangle1_Click()
                                Dim NewDisplay As Display
                                Dim OldContextPath As String
                                    Dim AFContext As ContextHandler
                                Set OldDisplay = ThisDisplay
                                    Set AFContext = Application.ContextHandlers("E")
                                    OldContextPath = AFContext.CurrentContext(ThisDisplay)
                                Set NewDisplay = Application.Displays.Open(NewDisplayPath, True)
                                    Application.ContextHandlers("E").CurrentContext(NewDisplay) = OldContextPath
                                    OldDisplay.Close
                                
                                End Sub
                                

                                 

                                  • Re: Passing the Element of Interest to a new screen
                                    Marcos Vainer Loeff

                                    Hi Scott,

                                     

                                    On my original example, I have used the method below when the button from the "Parent Display" is clicked:

                                     

                                     

                                     
                                    Private Sub cmdOpenChildDisplay_Click()
                                    
                                    Dim myPath As String
                                    myPath = ThisDisplay.Path
                                    myPath = Left(myPath, InStrRev(myPath, "\", -1, vbTextCompare))
                                    Dim myParentDisplay As Display
                                    Set myParentDisplay = ThisDisplay
                                    
                                    
                                    Dim ErdContextHandler As ContextHandler
                                    Set ErdContextHandler = Application.ContextHandlers("E")
                                    
                                    Dim myChildDisplay As Display
                                    Set myChildDisplay = Application.Displays.Open(myPath & "ChildDisplayERD.PDI", True)
                                    
                                    ErdContextHandler.CurrentContext(myChildDisplay) = ErdContextHandler.CurrentContext(myParentDisplay)
                                    
                                    
                                    End Sub
                                    

                                     

                                     

                                    You don't need any code on the second display.

                                     

                                    Hope it helps!!