7 Replies Latest reply on May 8, 2017 8:35 PM by AndyBantly

    How to programmatically change the AFDatabase?

    AndyBantly

      In C# code I would like to programmatically change the selected AF database.  For example, below are controls for a PI System Picker and an AF Database Picker.  I would like to programmatically tell the Database Picker to choose "NuGreen" and make it the active selection.  I've been looking at the documentation for the System and Database pickers but it is not obvious to me how to do the action.  Can someone answer this question?

       

        • Re: How to programmatically change the AFDatabase?
          tramachandran

          You can use AFDatabasePicker. AFDatabase property to get or set the current database or change the index using AFBasePicker. SelectedIndex property.

          2 of 2 people found this helpful
          • Re: How to programmatically change the AFDatabase?
            Rick Davin

            Hi Andy,

             

            I'm pretty sure Thyagarajan Ramachandran  has answered your question: use the AFDatabasePicker.AFDatabase property. You should consider marking his reply as the accepted answer.

             

            While it doesn't slap you in the face, the AFUIRef.chm file does show this for the AFDatabase property:

             

            public override AFDatabase AFDatabase { get; set; }

             

            Which indicates to you that the property is indeed settable.  Then again if you review the help page for the entire AFDatabsePicker Class, you will see this:

            2017-04-25 08_02_15-AF User Interface Library Reference.png

            All that said, I can't help but wonder if you need the picker at all.  For apps that I write, if I know the specific database beforehand, I would skip the UI dialog and just set the object directly.  If my app doesn't know the database beforehand, then I would present the UI picker to the end user.  If you need further guidance in these areas, just let us know.

              • Re: How to programmatically change the AFDatabase?
                AndyBantly

                I need the picker UI.  My firms clients use the PI sub-system of our application and I can't hardcode it.  I've been able to use the database picker and tree-view programmatically.  It works very well.  We let the end-user do data exploration using the UI.  We also script their actions into a runnable variant of visual basic and allow them to be played back for the same result.  I needed programmatic access to these controls b/c the end-user expects to see the UI choices of their last query after closing the dialog and reopening it.

                  • Re: How to programmatically change the AFDatabase?
                    Rick Davin

                    Hi Andy,

                     

                    I get that you're making an app that others will run.  Having programmatic access to the UI controls are what they are there for.  But in general for the AFDatabasePicker, its the end-user that actually selects the database the UI picker rather than have you set it via code.  Do your end-users have multiple databases or multiple PI servers that they work with?  If so, then yes by all means your application should offer the pickers.  However, if any given customes works with only 1 PIServer or only 1 AFDatabase, you could declare them in the app.config file and not have them have to take time to pick the one choice in the first place.

                     

                    What I'm guessing you might be doing with your app is saving their last chosen PIServer or AFDatabase back to the app.config file.  Next time they restart your application, then you programmatically set the pickers to their last known choice.  If that's the case, then I can understand why you would need both a picker and the need to explicitly set the objects.