PDA

View Full Version : Visual basic listboxes on forms


Matty919
02-03-2009, 08:10 PM
I have a listbox in visual basic on a form which has three types of fuel in:
Diesel
Petrol 95
Super 97

I added these via the properties menu. How do I assign a value to each of these types of fuel e.g.
Diesel = 100
Petrol 95 = 200
Super 97 = 90

Cheers.

demtron
02-03-2009, 08:51 PM
I assume you are using VB.Net. If you are binding a datasource (datatable, custom collection, etc.) to the control, you'll need to set DisplayMember and ValueMember on the control to identify what should be displayed vs. what is the underlying value of the item.

If you are adding list items at design-time, you'll need to set the Text and Value properties in each ListItem element.

Matty919
02-06-2009, 03:17 PM
Thanks I managed to fix that but now have a different problem.

Label6.Text = NumericUpDown1.Value * Format((CDbl(ListBox1.Text) / 100), "0 0 . 0 0")

This doesn't work and I can't seem to make it work. I want Label6 to display the numericupdown value multiplyed by the selected item in listbox1.text and then formatted in the format 0 0 . 0 0 e.g 9 formatted this way would be 0 9 . 0 0. I get the error

"Conversion from string "0 0 . 9 9" to type 'Double' is not valid."

Any help would be great.

demtron
02-06-2009, 08:37 PM
Try this:

Label6.Text = (NumericUpDown1.Value * CDec(ListBox1.Text) / 100).ToString("0 0 . 0 0")

Matty919
02-07-2009, 02:45 PM
Thank you that works perfectly. :)