I have Form1 that has a dataGridView and a button to add content to this Grid. When I select this button, I call the Form2 that has 2 TextBox and a ComboBox to fill in the Name, Directory, and Format (for example) in addition to a OK button to add the line to the dataGridView in Form1 .
When I get back on Form1 , the dataGridView must be showing the content entered. What happens is that my Grid has three columns: Name, Format and a button column to click on it to reload that screen of Form2 with the previously filled information loaded in each field again to be able to change or just check it out.
First I tried to create a function to add the lines to my Grid by parameters, as the code below shows:
Form 1
public Form1()
{
InitializeComponent();
}
public void AddRows(string nome, string path)
{
dataGridView1.Rows.Add(nome, path);
dataGridView1.Update();
}
Form 2
public Form2()
{
InitializeComponent();
}
private void bt1_Click(object sender, EventArgs e)
{
var nome = txt_nome.Text;
var path = txt_path.Text;
var form1 = new Form1();
form1.AddRows(nome, path);
}
However, it ended up not working, showing nothing on Grid. So I thought of creating a class with a name, path, and format ( get and set ) method to store everything in a list of objects (I think that's it forgive me if I'm wrong because I'm a beginner). Or save to a DataSet . But then I thought, I instantiate the class in my Form2 and pass the values filled in the fields, but there, what do I do in my Form1 ?
I think it's all very confusing, I'd be grateful if anyone could explain a clearer method of resolving this and please be specific as I'm a beginner.