CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Posts
    2

    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)

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    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))

  3. #3
    Join Date
    Oct 2004
    Posts
    2

    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.

  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    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.

  5. #5
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    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
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Display results in Listview

    ListView.Items(idx).SubItems(colnum).Text = "Whatever"

  7. #7
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    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

    To be precise, I can modify subitems created at design time, but how do I add a subitem at run-time?

    Thanks
    Last edited by DeepButi; October 29th, 2004 at 08:20 AM.
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  8. #8
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Display results in Listview

    DSJ,
    forget it ...

    ListView1.Items(index).SubItems.Add(value)



    Thanks
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  9. #9
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    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

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

Featured