Todd
Todd

Reputation: 3

Cycling through selected item in listview and populating another listview from subitem that has comma delimited subitem

I have a listview called lstProducts. The user selects an item in lstProducts to populate various objects in a form. Three of the subitems are comma delimited strings that must be parsed to populate lstAss.

I have code that cycles through but it is not parsing correctly:

Dim input As String = lstProducts.Items(x).SubItems(6).Text
        Dim result As String() = input.Split(New String() {","c}, StringSplitOptions.None)
        Dim m As String
        Dim t As String
        For Each s As String In result
            Dim inputT As String = lstProducts.Items(x).SubItems(10).Text
            Dim resultT As String() = inputT.Split(New String() {","c}, StringSplitOptions.None)
            Dim inputM As String = lstProducts.Items(x).SubItems(11).Text
            Dim resultM As String() = inputM.Split(New String() {","c}, StringSplitOptions.None)
            s = Trim(s)
            For Each t In resultT
                t = Trim(t)
            Next

            For Each m In resultM
                m = Trim(m)
            Next
            Dim li As New ListViewItem()

                li = lstAss.Items.Add(s, 0)
                li.SubItems.Add(t)
                li.SubItems.Add(m)
            Next

To be parsed:

col6: 1,2,3,4 col10: a,b,c.d col11: 96,97,98,99

Desired ouput:

col0
1
2
3
4

col1
a
b
c
d

col2
96
97
98
99

with my code lstAss is currently populating as follows:

col0
1
2
3
4

col1
d
d
d
d

col2
99
99
99
99

How do I get this to parse correctly? I have tried multiple ways to do this and this is as close as I have gotten.

The integrity of the data being fed into lstProducts is guaranteed through error handlers. There is a matching subitem in col6, col10, & col11.

Upvotes: 0

Views: 75

Answers (1)

Todd
Todd

Reputation: 3

I solved this. I simply combined the 3 subitems into 1 comma delimited string and parsed it back into the originating listview.

Dim input As String = lstSpecs.Items(x).SubItems(9).Text Dim result As String() = input.Split(New String() {","c}, StringSplitOptions.None)

    Dim li As New ListViewItem()

    For Each s As String In result
        s = Trim(s)
        If s <> "D" And s <> "C" Then
            li = lstSpecies.Items.Add(s)
        Else
            li.SubItems.Add(s)
        End If
    Next
End Sub

Upvotes: 0

Related Questions