2 Replies - 3506 Views - Last Post: 11 April 2011 - 11:50 AM Rate Topic: -----

#1 fre34y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 11

how to use the listview tool with check boxes

Posted 11 April 2011 - 11:18 AM

I am using visual studio 2008. I need to use the listview tool with checkboxes instead of the checked list box as with the ListView the properties can be set that the user can only have one choice.

Problem: I am not sure on the code to manipulate what option has been picked. I want it to output the same as the code below. I know how to manipulate a checked list boxes by the example code below:


   If (ChkdListChoice.SelectedIndex = 2) Then
       LstDisplay.Items.Add("Spicy Chicken - 3.50")
       price = price + 3.5
   End If





Obviously a ListView is different, I thought that it maybe was something like:

        If (LstvChoice.CheckedIndexCollection = 0) Then
            LstDisplay.Items.Add("Margarita - 2.50")
            price = price + 2.5
        End If



This is what I have understood from the msdn website. If anyone could help me out it would be great!

Is This A Good Question/Topic? 0
  • +

Replies To: how to use the listview tool with check boxes

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9215
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: how to use the listview tool with check boxes

Posted 11 April 2011 - 11:31 AM

If you have the listview constrained to no multiple selections, why not use the 'selected items' function? Sure that returns a collection of selected items, but we know there will only be one, right? Make sure to check there *are* items in thatl ist.

if Me.ListView1.SelectedItems isnot nothing
  '-- do stuff using this:
  '--  Me.ListView1.SelectedItems(0)
end if



that should get you one list view item object!

http://msdn.microsof...ecteditems.aspx

listviewitem
http://msdn.microsof...stviewitem.aspx
Was This Post Helpful? 0
  • +
  • -

#3 fre34y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 11

Re: how to use the listview tool with check boxes

Posted 11 April 2011 - 11:50 AM

Thanks, I sort of get that but will this then more less do something similar to the code below that I had for a checked list box?

when you write:
 Me.ListView1.SelectedItems(0) 


how would i use that?

This is my code for checked list box which worked and seemed simpler to me only I cant restrict the multi-select property.

        If (ChkdListChoice.SelectedIndex = 0) Then
            LstDisplay.Items.Add("Margarita - 2.50")
            price = price + 2.5
        End If

        ElseIf (ChkdListChoice.SelectedIndex = 1) Then
        LstDisplay.Items.Add("Mexican Hot - 3.50")
        price = price + 3.5

        ElseIf (ChkdListChoice.SelectedIndex = 2) Then
        LstDisplay.Items.Add("Spicy Chicken - 3.50")
        price = price + 3.5

        ElseIf (ChkdListChoice.SelectedIndex = 3) Then
        LstDisplay.Items.Add("Maryland - 3.00")
        price = price + 3.5

        ElseIf (ChkdListChoice.SelectedIndex = 4) Then
        LstDisplay.Items.Add("American Special - 3.50")
        price = price + 3.5

        ElseIf (ChkdListChoice.SelectedIndex = 5) Then
        LstDisplay.Items.Add("Hawaiian - 2.75")
        price = price + 2.75

        ElseIf (ChkdListChoice.SelectedIndex = 6) Then
        LstDisplay.Items.Add("Meat feast - 4.00")
        price = price + 4.0

        ElseIf (ChkdListChoice.SelectedIndex = 7) Then
        LstDisplay.Items.Add("Vegeterian - 3.50")
        price = price + 3.5

        Else
        LstDisplay.Items.Add("Spicy Beef - 3.75")
        price = price + 3.75

        End If


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1