When I add an item to the datagridview (from another form), it shows up just fine. But when I try to add another item to the datagridview, only the new item appears, and the previous one gets thrown out, it appears.
Note that I'm using .Hide, and .Show, to move between two forms (add_form and main_form). I've tried using .ShowDialog to see if it would fix the problem, but instead I get multiple instances of the same window open after moving back and forth between forms.
How can I fix this problem?
Here is the code that adds to the DGV:
private void add_Click(object sender, EventArgs e)
{
//OBJECT REFERENCE TO DGV
invmain invmainobject = new invmain();
//SWITCH STATEMENT FOR DIRECTING USER-ENTERED INVENTORY DATA
//TO THE APPROPRIATE TABCONTROL TAB AND DGV<1:4>
switch(combobox1.SelectedIndex)
{
case 0: //ELECTRICAL
invmainobject.datagridview1.Rows.Add(itembox.Text, quantitybox.Text);
break;
case 1: //MECHANICAL
invmainobject.datagridview2.Rows.Add(itembox.Text, quantitybox.Text);
break;
case 2: //CABLES
invmainobject.datagridview3.Rows.Add(itembox.Text, quantitybox.Text);
break;
case 3: //MISC.
invmainobject.datagridview4.Rows.Add(itembox.Text, quantitybox.Text);
break;
default:
MessageBox.Show("Please select a category.\t\t");
combobox1.Focus();
return;
}
invmainobject.Show();
this.Close();