Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For example I have this listview table:
ID   |Item    |Qty 
001   item1    1
002   item2    0
003   item3    2
004   item4    0


Note: the table is ever adding if the user wanted to. So there may be a countless items in a single run.

My problem is, I'm having trouble checking each row for 0s.

My plan is before it adds all the item to my database, it should check for any 0 quantities and prompt the user to put a value on those 0s before proceeding.

What I have tried:

C#
private void StockReqItemAdd_Click(object sender, EventArgs e)
        {
            if (StockReqItemDataChosen.Items.Count == 0)
            {
                MessageBox.Show("Please add item/s before proceeding!");
            }
            else
            {
                for (int i = 0; i < StockReqItemDataSelect.Items.Count; i++)
                {
                    if (StockReqItemDataSelect.Items[i].SubItems[3].ToString() == "0")
                    {
                        MessageBox.Show("Don't leave empty quantities on the items!");
                    }
                    else
                    {
                        addstockmenu();
                        delall();
                        loaddata();
                    }
                }
               
            }
            
        }


It still adds even with 0s and is looping the message box.
Posted
Comments
Bryian Tan 18-Jun-18 21:54pm    
You need to add break; to the code after the MessageBox.Show("Don't leave empty quantities on the items!"); to prevent the code from going further if 0 quantity.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900