How to access parent form class variable

It all depends on the heirarchy of your forms.

- Form1
   - RepeatingPanel
      - ItemTemplate

Where does your class variable live in relation to the heirarchy? Is it Form1?
Is Form1 the open form?
If yes then you should be able to do

get_open_form().my_variable

You could access it via parents

# from the item template
self.parent.parent.my_variable

I would try to avoid using too many parents though - if you get to 3 parents then there’s a better way. Even with 2 parents I’d think twice.
(I avoid multiple parents because if you later decide you need a card component within this hierarchy well then your line of parents is now all wrong!)

You could also pass the Form1 instance to the item templates in some fashion. Since Form1 is an object you can pass it around as you like.

If you need more it would be useful to see more code snippets.

3 Likes