i was doing an ordering interface and i got stuck at the point of the delete.
e.g: order interface
at starting, i will click the 'Add to Order' button, which does the multiplication of the foodprice and quantity then store into an array.
private int c = 0;
private decimal[] ordersarray = new decimal[10];
List<decimal> items = new List<decimal>();
private void fconfirmbutton_Click(object sender, EventArgs e)
{
int fquantity;
if (int.TryParse(fquantitytextbox.Text, out fquantity))
{
fquantity = int.Parse(fquantitytextbox.Text);
if (fquantity.ToString() != "" + 0)
{
decimal mulxprice, quan, total;
mulxprice = decimal.Parse(fpricetextbox.Text);
quan = int.Parse(fquantitytextbox.Text);
total = mulxprice * quan;
cartlistbox.Items.Add(foodnametextbox.Text + " x" + quan.ToString() + " ($" + total.ToString() + ") ");
subtotalbox.Text = total.ToString();
decimal b;
try
{
if (decimal.TryParse(subtotalbox.Text, out b))
{
ordersarray[c] = b;
c++;
subtotalbox.Text = "";
}
}
catch
{
MessageBox.Show("Sorry, the order system can only takes up to 10 orders at a time only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
fquantitytextbox.Clear();
fquantitytextbox.Focus();
}
after it is stored into the cartlistbox and ordersarray, i try to delete it by using :
EDIT :
private void deletebutton_Click(object sender, EventArgs e)
{
try
{
if (this.cartlistbox.SelectedIndex >= 0)
{
cartlistbox.Items.Remove(cartlistbox.SelectedItem);
cartlistbox.Refresh();
}
else
{
MessageBox.Show("Error, please select an item to delete.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
for instance, i might order 2 items, e.g:
so i attempt to delete item 'b', by selecting it from the listbox and clicking the 'Delete' button, however it always ends up with "index was outside the bounds of the array". so i understand that this was sort of the array crashing after removing of the array value completely, but i have no idea how.
im sorry as this may be confusing but i hope you understand what i might need.