What im trying to do:
- Search products by BarCode on
Form1form; - if it cannot be found:
1. OpenInventoryform
2. Search product by name or description
3. OnListView clickon the found product copy its BarCode and paste it to theForm1barcode textbox.
All that is done corectly. The problem is that every time I add product from Inventory form a new Form1 is opened.
The values are not processed in the same Form1, so assume I sell 4 products:
- 2 of them are added through
Form1barcode search - 2 of them are added through
Inventorysearch form
In the end I get 3 opened Form1 forms, one with 2 products and two forms with single product (added through Inventory form). I need them to be all in one.
Thanks
//————————-Form1——————————————–
private void btnInventory_Click(object sender, EventArgs e)
{
Inventory Inventory = new Inventory();
Inventory.Show();
}
private string _theValue;
public string TheValue
{
get
{
return _theValue;
}
set
{
_theValue = value;
txtItems.Text = value;
}
}
//—————————–Inventory———————————
private void ShowForm1()
{
string value = label9.Text;
Form1 newForm = new Form1();
newForm.TheValue = value;
this.Close();
newForm.ShowDialog();
}
private void lvList_Click(object sender, EventArgs e)
{
label9.Text = lvList.SelectedItems[0].SubItems[0].Text;
this.ShowForm1();
}
Im sorry for the delay, i had to wait 8h before posting again
Thanks for ur reply.
I just tried that
Form1
private void btnInventory_Click(object sender, EventArgs e)
{
Inventory _inv = new Inventory();
if (DialogResult.OK == _inv.ShowDialog())
{
txtItems.Text = _inv.fugi;
}
}
and in Inventory Form
private string test;
public string fugi
{
get { return test; }
set { test = label9.Text; }
}
private void lvList_Click(object sender, EventArgs e)
{
label9.Text = lvList.SelectedItems[0].SubItems[0].Text;
this.DialogResult = DialogResult.OK;
this.Close();
}
txtItems.Text does not get the value of test from inventory form
Its opening a new dialog because you tell it to in
ShowForm1, Personally I would change your btnInventory click as followsAccessor you will need to make yourself similar to
Edit:
Once you have gotten the value of your barcode you need to set
DialogResultas Followsand then set the variable you wish to access to the barcode before closing your form
Edit2:
Your
ShowForm1will end up similar to this (May want to rename this method!)UPDATE ANSWER
You are still having problems as you haven’t used the
setproperty correctly, your get is fine as it is. There is a keyword in c# calledvaluethat should be used for setters. this value will take the value of whatever is on the right hand side of an = sign.. you can think of it like this…fugi = label9.TextIn the above line,
fugiis using your properties getter in order to get the value that needs to be set tolabel9.Text. The=sign says that you intend to use the setter for this property and set the value ofvaluetolabel9.Text.Properties with a getter and setter are used so you do not have to provide access to the underlying variable to somewhere you would not like to and then can have the option to just set or get this variable as needed.
This means that your problem persists have you have yet to set the value of
test, it is still the default string value.So you have a couple of ways to solve your problem.
The first way is just to provide a getter for label9.Text and remove the need for your private variable.
The second is to set the value of test before you call your getter in btnInventoryClick and remove the setter method
and the third ist to set
testas shown in method 2 but also change the set method of Fugi to the following to allow this test variable to be set elsewhere.set{text = value;}