I have one main form called frmMain
and two textboxes on that called txtCustomer
and txtProduct
and two buttons called btnInsertCustomer
and btnInsertProduct
.
I then have two forms called frmCustomer
and frmProduct
. In each form I have a dataGridView which shows the information of customers and products respectively.
I want for example when I click on btnInsertCustomer
the frmCustomer
opens and I can double click on the dataGridView in this form. When I do, it should insert the value of field customerCode
into txtCustomer
in frmMain
.
Then I want to click on btnInsertProduct
and frmProduct
will open and I can double click on one row on dataGridView
and insert the value of field productCode
into txtProduct
in frmMain
without loosing the value of txtCustomer
that I have inserted earlier.
I can get only one value from one of the forms into my main form with my current approach. I made an identifier of txtCustomer
and txtProduct
assigned to public. Then on the event of CellDoubleClick
of dataGridView
of frmCustomer
I wrote this code:
frmMain fr = new frmMain();
fr.txtCustomer = dgv1FrmCustomer.SelectedRows[0].Cells[1].Value.ToString();
fr.Show();
and the same code for the frmProduct
. The problem with this method is that I can only get data from one form. When I open the other form and select a row the data on the previous textbox is gone. I wonder how I can get data from both forms?