Good day!
I have a piece of code in a button, which counts updates and deletes from the database. To insert a new form is opened , and when inserted it returns to the main form .
My question is, how can I do so that when I return from the insert form to the main one, it updates automatically (without clicking the button)?
I attach code, thanks.
private void LoadCounters()
{
// get contact counters for current login
var dic = DaoWaybill.GetReceiverInformation(Constants.strIdUser, Constants.strUsername);
lblGuides.Text = dic.FirstOrDefault(x => x.Key == "guides").Value;
lblContactIncident.Text = dic.FirstOrDefault(x => x.Key == "total_incident").Value;
lblContactConfirmed.Text = dic.FirstOrDefault(x => x.Key == "total_confirmed").Value;
}
Current button code ( Click event ):
private void radButton2_Click(object sender, EventArgs e)
{
LoadCounters();
}
As gbianchi comments , you can "wire" two forms so that the child accesses methods of the parent when needed.
You can achieve this by passing the parent form to the child form's constructor.
This approach sometimes forces a form's internal methods, or properties, to be public, in order to be accessible from the child form.
A somewhat more selective alternative might be to pass the counter refresh action itself to the child form's constructor.