I have a project which is 98% complete. Its basically a Shop(till) interface. I have a form that has tabs the first being the main till, second shows a listview with everything in stock and the quantity of items in stock. Im stuck on one part of the program where when the form loads it checks the stock and if any of the items have a quantity less than 5 for example than it displays a message box to the user telling him/her to order new stock, but im not sure exactly how to do that. Can someone help me or guide me as to how i can do this?

i was also thinking if it was possible to colour the quantity in red? so when the user clicks on the stock tab then they could see that its running low and he/she will need to order more.

thanks

See if this helps to change BackColor of items in a ListView.

For Each itm As ListViewItem In ListView1.Items '// loop thru all items.
            If itm.Text <= CStr(5) Then '// check if value is less than or equals 5.  CStr = Convert to String, since using an Integer.
                itm.BackColor = Color.Orange '// change BackColor.
            Else
                itm.BackColor = ListView1.BackColor '// if not <=5, set itm BackColor to ListView.BackColor.
            End If
        Next

If a .SubItem, replace # with the Column #. If itm.SubItems(#).Text <= CStr(5) Then You should have no trouble adding a MsgBox as needed.

Edited 5 Years Ago by codeorder: typo

See if this helps to change BackColor of items in a ListView.

For Each itm As ListViewItem In ListView1.Items '// loop thru all items.
            If itm.Text <= CStr(5) Then '// check if value is less than or equals 5.  CStr = Convert to String, since using an Integer.
                itm.BackColor = Color.Orange '// change BackColor.
            Else
                itm.BackColor = ListView1.BackColor '// if not <=5, set itm BackColor to ListView.BackColor.
            End If
        Next

If a .SubItem, replace # with the Column #. If itm.SubItems(#).Text <= CStr(5) Then You should have no trouble adding a MsgBox as needed.

it doesnt seem to work. i dont get any error at all it just doesnt work. the program just runs at it always did

Try this in a New Project.
1 TabControl and 1 ListView with items(in TabPage2)

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedIndex = 1 Then '// if TabPage2.
            '// checkStockItemsStatus(ListView Name that you are using, Column # that you need to check(starts at 0 not 1), # of minimum allowed qty.)
            checkStockItemsStatus(ListView1, 4, 5)
        End If
    End Sub

    Private Sub checkStockItemsStatus(ByVal selectedListViewToCheck As ListView, ByVal ColumnToCheckValueFor As Integer, ByVal MinimumAllowedQuantity As Integer)
        For Each itm As ListViewItem In selectedListViewToCheck.Items '// loop thru all items.
            If CInt(itm.SubItems(ColumnToCheckValueFor).Text) <= MinimumAllowedQuantity Then '// check if value is less than or equals MinimumAllowedQuantity.
                itm.BackColor = Color.Orange '// change BackColor.
            Else
                itm.BackColor = Color.LightGreen
            End If
        Next
    End Sub

Edited 5 Years Ago by codeorder: n/a

Attachments lv.png 12.66 KB

Seems to work but now im stuck on how id display, in a message box, which items are low on stock.

This question has already been answered. Start a new discussion instead.