The parent form of my windows form application (Point Of Sale Application) has a grid view with data from the database like Product Name, Quantity and Unit Price (excluding Quantity as I have set its default value to 1). Here is my code:
string productName = dr[0];
int quantity = 1;
int unitPrice = Convert.ToInt32(dr[1]);
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgvAllSoldItems);
row.Cells[0].Value = productName;
row.Cells[1].Value = quantity;
row.Cells[2].Value = unitPrice;
row.Cells[3].Value = (quantity * unitPrice);
dgvAllSoldItems.Rows.Add(row);
What I want is to allow my users to update the quantity amount of specific items if required. I want this to be accomplished using a child form. The child form will have a text box on it for the quantity (custom quantity).
I have configured the child form and I am able to show it upon double-clicking the target product (the data grid view row). What I want is to allow users to replace the default value of quantity [int quantity = 1;
] on the main form with a custom value that the user will put on the text box located on the child form.
I am only having a problem in passing this custom quantity (text box value) from the child form to my parent form. So far, I have used the following code for passing the text box value to my parent form and I am lucky enough to get the text box value in the public method [GetSoldItemQuantity
] on my parent form.
public void GetSoldItemQuantity(string customQuantity)
{
string globalQuantity = customQuantity;
}
At this point, I always get the custom quantity value from the child form in string globalQuantity
but I am unable to assign this value back to int quantity
or replace its existing value with this one.
Here is the button click code on my child form that pass the custom quantity value from text box to the public method on my parent form.
private void btnPassCustomQuantityToParentForm_Click(object sender, EventArgs e)
{
string newItemQuantity = txtCustomQuantity.Text;
frmSale newSale = new frmSale();
newSale.GetSoldItemQuantity(newItemQuantity);
this.Close();
}
How can I pass this custom quantity to the quantity variable whose default value is 1 in my first code snippet?