Working with database on multiple forms

  • Thread starter Thread starter GianBraghini
  • Start date Start date
G

GianBraghini

Guest
Hello!

Im having some issues regarding Database and multiple Forms. Let me explain the situation first:

My previous software worked all fine, and it were on only one Form, with the other windows becoming visible and invisible as I needed it. The thing is, the user didnt like... well, neither I liked it hehe. So I started developing those windows in new Forms, but it didnt work so well.

I have three Forms, the main one is where the user can see the projects he have, so I just dragged the components from the database that I needed to display (it worked on the only-one-form-project), the Form2 which the user register his projects and the third one that edits some details of the the project.

So, the main form contains three datagridviews, side-by-side, each one with different contents from the user project, and all dragged from the database, and thats where lays down my problem. See, with the only-one-form-project I was able to update these datagridviews as I edited the other windows (by pressing a save button). But now, from other forms, I cant do it.

The database saves the data, because when I reopen those other forms, the edited data is there, although it doesnt update in the gridviews.

Ive dragged the same components from the database on both projects (the only-one-form and the multiple forms), but it only works on the only-one-form and I cant figure out a solution. I can only assume that it is because they are on different forms.

Heres some code snippets:


//THE MAIN FORM
public partial class PRINCIPAL : Form
{
/*
Some variables were here
*/
//the declaration of the other forms
Form3 Config = new Form3();
Form2 Cadastro = new Form2();

public PRINCIPAL()
{
InitializeComponent();
}
//When it loads the main form, it fill each of the datagridviews
private void Form1_Load_1(object sender, EventArgs e)
{
this.funcaoTableAdapter.Fill(this.database1DataSet.Funcao);
this.estadosTableAdapter.Fill(this.database1DataSet.estados);
this.modulosTableAdapter.Fill(this.database1DataSet.Modulos);
this.projetoTableAdapter.Fill(this.database1DataSet.Projeto);
WindowState = System.Windows.Forms.FormWindowState.Maximized;
timer1.Start();
}

//THIS! this is the save method used.

//It worked just fine on the only-one-form-project and yesterday

//I was able to call this method from the other forms.

//But, well, though I called it, the datagridview didnt show the new data
public void salva_banco()
{
Validate();
projetoBindingSource.EndEdit();
modulosBindingSource.EndEdit();
funcaoBindingSource.EndEdit();
estadosBindingSource.EndEdit();
tableAdapterManager.UpdateAll(database1DataSet);
}
//It had this. before each statement, do I tried removing it.. well, didnt work also.

//THE OTHER FORMS

//this is how I call the save method:
var principalForm = Application.OpenForms.OfType<PRINCIPAL>().Single();
principalForm.salva_banco();

//Ive added breakpoints to see if it actually calls the method, and it does.



Well, I havent remove completely the other windows, I mean, when I open Form2 it also opens the old edit window on the main form. Ive tried to remove it, but it seems that the problem continues, perhaps something I left behind. If anyone could help, I would be really happy.

Any doubts about how the program works, just ask.

ps.: Ive tried to upload some images, but MS said they need to verify my account... thanks a lot MS, hehe.

Thanks!

Continue reading...
 
Back
Top