Hello, I am having issue retrieving the value of a certain application setting then making it increment (++)
public int orderIDnumber ;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
orderIDnumber = Properties.Settings.Default.OrderID; //Read the last order number from user settings
orderIDnumber ++; //Increase the order number by one ready to take an order
ordernumLBL.Text = orderIDnumber.ToString(); //Display the order number in the label on screen after converting it to string
}
private void Newordernum()
{
orderIDnumber++; //Increase order number by 1 (++ means increase by 1)
ordernumLBL.Text = orderIDnumber.ToString();
}
private void neworderBTN_Click(object sender, EventArgs e)
{
Saveorder();
Clearlists();
Clearboxes();
Newordernum();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.OrderID = orderIDnumber;
Properties.Settings.Default.Save();
}
Once I click a button I want it to update the label text but nothing is happening, seem the value is staying at 0 all the time.
You are reading the value of Properties.Settings.Default.OrderID
into the field orderIDnumber
. After that you are incrementing the field, leaving the original setting value unchanged.
You have to write the new number back into the setting eventually. Finally you need to call the save method to persist the new value:
Properties.Settings.Default.OrderID = orderIDnumber;
Properties.Settings.Default.Save();