Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15715

Can Someone help me to correct the following code for SelectedItems and its Subitems

$
0
0
Hello
Can Someone help me to correct the following code for SelectedItems and its Subitems in Listview as per proper columns


Code:

My listview1 is Displayed as from Excel range
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40

Code:

Private Sub CmdAddFruits_Click(sender As Object, e As EventArgs) Handles CmdAddFruits.Click

ListView1.Items.Clear()

For selItemsCount As Integer = 0 To ListView1.Items.Count - 1
      If ListView1.Items(selItemsCount).Checked = True Then
                ListView1.Items.Add(ListView1.Items(selItemsCount).Text.ToString())

              For selSubitems As Integer = 0 To ListView1.Items(selItemsCount).SubItems.Count - 1
                  ListView1.Items.Add(ListView1.Items(selItemsCount).SubItems(selSubitems).ToString())
                Next
            End If
        Next

End Sub

After Selecting any of the Fruits or
for eg. i selected only Banana and Kiwi and pressed CmdAddFruits i get

Code:


My listview1 is Displayed as
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Banana}
CHKBOX ListViewSubitem:{40}
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Kiwi}
CHKBOX ListViewSubitem:{60}
     

Actaully Wanted Display as
     
      Product      Name  Qty
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60

Also Listview1.Items.Clear() Clears the full list view and when above items added it does not display anything
Thanks

SamD
Thread 10 892479
50

Viewing all articles
Browse latest Browse all 15715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>