There are several ways to implement this situation, you could better describe your situation to help with the best way for your case.
Whereas you will block Form1 while form2 is open, and when "write" to form2, it closes, returning to Form1, it can be done as follows:
1- In the event where you open form2, use Showdialog and if you return OK, you search the data again for listview. In form2, at the end of the "Record" event enter: "this.Dialogresult = System.Windows.Forms.DialogResult.OK;"
Code of Form1:
public Form1()
{
InitializeComponent();
}
public void AtualizaListView()
{
//Vai no banco de dados, e atualiza o listview
}
private void buttonInserir_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
if ( form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
AtualizaListView();
}
}
Form2:
public Form2()
{
InitializeComponent();
}
private void buttonGravar_Click(object sender, EventArgs e)
{
try
{
//Grava no banco de dados
//Se tudo estiver correto,
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Now, if you need to keep Form2 open, and still update Form1, in Form1 state the search method in the database as public, and pass the Form1 object as parameter to Form2. In Form2 Save, run the search method in the database present in Form1. Code Example:
Form1:
public Form1()
{
InitializeComponent();
}
public void AtualizaListView()
{
//Vai no banco de dados, e atualiza o listview
}
private void buttonInserir_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.form1 = this;
form.Show();
}
Form2:
public Form1 form1 { get; set; }
public Form2()
{
InitializeComponent();
}
private void buttonGravar_Click(object sender, EventArgs e)
{
try
{
//Grava no banco de dados
//Se tudo estiver correto,
form1.AtualizaListView();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Improve the question to have more chances of answer. https://pt.meta.stackoverflow.com/questions/1186/como-crea-um-exemplo-m%C3%Adnimo-completo-e-verific%C3%A1vel? Rq=1
– Pagotti