Have the parent forms implement an interface:
public interface ISetAccountDetails
{
int AccountId { set; }
string AccountName { set; }
}
public class ADDSickFiling : Form, ISetAccountDetails
{
...
int ISetAccountDetails.AccountId
{
set { ReferenceAccountId = value; }
}
string ISetAccountDetails.AccountName
{
set { ReferenceAccountTextBox.Text = value; }
}
}
public class ReportCashierByAccOne : Form, ISetAccountDetails
{
...
int ISetAccountDetails.AccountId
{
set { CashierID = value; }
}
string ISetAccountDetails.AccountName
{
set { CashierNameTextBox.Text = value; }
}
}
public class ReportDrugStoreBill : Form, ISetAccountDetails
{
...
int ISetAccountDetails.AccountId
{
set { CashierID = value; }
}
string ISetAccountDetails.AccountName
{
set { CashierNameTextBox.Text = value; }
}
}
Then use that interface to update the parent:
if (mdiparent is ISetAccountDetails setAccount)
{
setAccount.AccountId = Convert.ToInt32(GridViewService.CurrentRow.Cells["AccountId"].Value.ToString());
setAccount.AccountName = GridViewService.CurrentRow.Cells["AccountName"].Value.ToString();
}
interface - C# Reference | Microsoft Docs[
^]