Display results in Listview
Newbie. I have a menu with a checkbox (chkHamburger), a combobox for the quanity (cboHamburger). When I click the check box for Hamburger and select the Quanity, I would like for it to be displayed in the List View box. Below is the code I have written my my button click event.
Dim dblHamburger As Double
cboHamburger2.SelectedIndex = -1
If chkHamburger.Checked = True Then
Select Case cboHamburger2.SelectedIndex
Case 0
dblHamburger = 1.99
Case 1
dblHamburger = 2 * 1.99
Case 2
dblHamburger = 3 * 1.99
Case 4
dblHamburger = 4 * 1.99
Case 5
dblHamburger = 5 * 1.99
End Select
Else
dblHamburger = 0.0
End If
If I send this to a messagebox I get zero when i select any quanity:
MessageBox.Show(dblHamburger)
Re: Display results in Listview
You're getting zero because you're setting cboHamburger2.SelectedIndex = -1, so you Case Else is the one always executing. Moreoever, get rid of the case statement altogether!!
if cboHamburger2.SelectedIndex <> -1 then
dblHamburger = (cboHamburger2.SelectedIndex + 1) * 1.99
else
dblHambruger = 0
end if
Msgbox (cstr(cblHamburger))
Re: Display results in Listview
Cool got the msgbox to work with a little bit of tweaking. Now how would I incorporate the listviewbox (lstOrder) to show on one line the Quanity, Item (different hamburgers), and Price.
I have a listviewbox called lstOrder with those three columns: Quanity, Item, and Price.
Re: Display results in Listview
By "ListViewBox" do you mean ListBox or ListView? I would use a ListView personally. If that's what you mean, put one on your form and edit it's Style to "Detail" and edit it's Column property to add your columns. Then in your code where appropriate, add new ListItems as needed.
Re: Display results in Listview
DSJ,
that's clear, but how do you put each value into each column?
Listview1.Items(item_number).Text refers only to the first column, how do you get access to every single column?
Thanks
Re: Display results in Listview
ListView.Items(idx).SubItems(colnum).Text = "Whatever"
Re: Display results in Listview
DSJ,
that's what I thought ... but I keep getting a System.ArgumentOutOfRangeException when I use colnum greater than 0, even if I can add subitems at design time :ehh:
To be precise, I can modify subitems created at design time, but how do I add a subitem at run-time?
Thanks
Re: Display results in Listview
DSJ,
forget it :blush: ...
ListView1.Items(index).SubItems.Add(value)
:blush:
Thanks
Re: Display results in Listview
Dim i As Integer
Dim c As Integer
For c = 0 To 4
ListView2.Columns.Add(New ColumnHeader)
ListView2.Columns(c).Text = "Col" & c.ToString
Next
For i = 0 To 10
Dim li As New ListViewItem("Item " & i.ToString)
For c = 1 To 4
li.SubItems.Add("Col " & c.ToString)
Next
ListView2.Items.Add(li)
Next