7 Replies Latest reply on Apr 30, 2013 5:42 AM by alex_drugai

    The construction of AFTree

    alex_drugai

      Hi everyone!!
      Can anybody help me with question, how can i make my AF Tree show only Elements and its Attribute. We had three database and all of them are in the TreeView, but i need only one. In current time my AFTree show the full hiearchy. iThink its easy but im newbie of development so need help. This is the 1st question

       

      the 2nd question is:
      Is it some function or event with selected nodes of my af tree. For example, i need open display from the directory by clicking on some attribute (node) in my Tree.
      And the last question =) May be its easy to build my own treeview, with own nodes (attributes,elements) and add it to the application?

       

      Thanks for replies and sorry for my English, hope you understand me.

        • Re: The construction of AFTree
          Rick Davin

          To answer your first question: Let's assume you have an AFDatabasePicker control named afDatabasePicker1.

           

          In your form's constructor or load event, you will want to have this snippet of code: 

           

           

           
          afTreeView1.ShowAttributes = true;
          

           
          You will also need to have something like this in the SelectionChange event for the database picker:

           

           

           
                  private void afDatabasePicker1_SelectionChange(object sender, OSIsoft.AF.UI.SelectionChangeEventArgs e)
                  {
                      // this displays just the elements for the selected database:
                      afTreeView1.AFRoot = (afDatabasePicker1.AFDatabase != null) ? afDatabasePicker1.AFDatabase.Elements : null;
                  }
          

           

            • Re: The construction of AFTree
              tseiferth

              The approach above will work well.

               

              If you want to show your database in the tree and only show elements then you have to unset the Show* properties for the other types:

               

              ShowElements, ShowEventFrames, ShowElementTemplates, etc. So set all the Show* properties to false except for ShowElements and ShowAttributes (ensure these are set to true) then set your AFRoot to a database.

                • Re: The construction of AFTree
                  Rick Davin

                  To answer the 2nd question, you may want to check the AfterSelect event of the AFTreeView along the lines of:

                   

                   

                   
                          private void afTreeView1_AfterSelect(object sender, TreeViewEventArgs e)
                          {
                              var tv = sender as AFTreeView;
                              object selection = (tv != null) ? tv.AFSelection : null;
                              AFAttribute attribute = null;
                              AFElement element = null;
                              if (selection is AFAttribute)
                              {
                                  attribute = (AFAttribute)selection;
                                  element = (AFElement)attribute.Element;
                              }
                              else if (selection is AFElement)
                              {
                                  element = (AFElement)selection;
                              }
                              // Now do whatever with attribute and/or element
                              // but remember they could be null
                          }