List boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jani123
    New Member
    • Aug 2007
    • 1

    List boxes

    Hi

    Im new to this forum,, I need to know how to select an item in a list box. After selecting the item i want assign the specific item to a variable

    Im working on exercise. We are told to add prices of products to a list box and to SUM the prices and show in a label.

    Thanks
    Pls help
  • samycbe
    New Member
    • Feb 2007
    • 83

    #2
    step 1: have list boxes with list data from table (eg : material)
    step 2 : code for list1_dblclick( )
    check list1.text's equalent price from table and fill it in label

    Comment

    • JonJacobs
      New Member
      • Aug 2007
      • 22

      #3
      Originally posted by jani123
      Im working on exercise. We are told to add prices of products to a list box and to SUM the prices and show in a label.
      In light of the stated goal, I interpret your use of "select" simply to mean that you want access to each item in the listbox and the ability get each one in to a variable, rather than user selection of one or more items.

      Code:
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
              Dim Price As Double
              Dim Total As Double = 0
      
              For Each S As String In ListBox1.Items
                  Price = CDbl(S)
                  Total += Price
              Next
      
              Label1.Text = Total.ToString("C")
          End Sub
      HTH

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I think we need to know what version of VB is being used. I use VB6, so that code definitely wouldn't work for me.

        Comment

        Working...