Click to See Complete Forum and Search --> : Display results in Listview
ncgringo
October 27th, 2004, 01:27 PM
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)
DSJ
October 27th, 2004, 03:14 PM
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))
ncgringo
October 28th, 2004, 10:59 AM
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.
DSJ
October 28th, 2004, 04:03 PM
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.
DeepButi
October 29th, 2004, 07:05 AM
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
DSJ
October 29th, 2004, 08:03 AM
ListView.Items(idx).SubItems(colnum).Text = "Whatever"
DeepButi
October 29th, 2004, 08:17 AM
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
DeepButi
October 29th, 2004, 08:23 AM
DSJ,
forget it :blush: ...
ListView1.Items(index).SubItems.Add(value)
:blush:
Thanks
DSJ
October 29th, 2004, 09:51 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.