I’m confused

Master grid selected row value

I have a table which i use as a master grid with all the companies listed on the system. I have a child table which is in a tab once a company is selected.
When i create a new record in the child table i want to find out the master record's companyid that is selected and then use this companyid to do some calculations in order to populate some fields in the create form.
I am not sure how to get the companyid of the selected row? And where would i put the logic of populating the fields with the calculated values? Would it be in:
1 person has
this question