Results 1 to 9 of 9

Thread: Listbox: Display a name but also have a hidden price value

Threaded View

  1. #8
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Listbox: Display a name but also have a hidden price value

    Quote Originally Posted by redneckrider View Post
    I just need help declaring the name with a value in the list box.
    And How do I list each listbox number so I can retrieve it back as a price value to put in a formula. Thank you.
    If that's all you want to do, then you can simply swap your listbox for a listview.

    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         'create a listview, set View to "List"
    3.  
    4.         'adding a book you can do this:
    5.         Dim book As ListViewItem = New ListViewItem
    6.         book.Text = "Put your book title here"
    7.         book.SubItems.Add("19.99")
    8.  
    9.         ListView1.Items.Add(book)
    10.  
    11.         'It will only display the book title, and keep the Price Associated with it.
    12.     End Sub
    13.  
    14.     Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    15.         'now to get the amount:
    16.         Dim bookprice As Decimal = Decimal.Parse(ListView1.Items(0).SubItems(1).Text)
    17.  
    18.         'example
    19.         Me.Text = bookprice
    20.     End Sub
    Last edited by stepdragon; Nov 4th, 2011 at 01:33 PM. Reason: forgot the type on bookprice

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width