0

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.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Todd
  • 1
  • 1
  • I am not sure if this is possible or if my question is confusing. Anyone have any ideas how to solve this? Thank you. – Todd Aug 14 '22 at 17:01
  • Really not to sure exactly why you're doing the loops over resultT and resultM. Suspect that might be where you're falling over as it will always the value of t and m to the last element of those two collections. Would look at consolidating those down to a single loop. That said though, from your question, it's not clear which element of those collections goes with what record in your intended output – Hursey Aug 15 '22 at 03:55
  • Here is what I am attempting to do: The selected row in lstProducts contains three columns of comma delimted text. They originated from a three-colum listview called lstAss. When the user selects a row in lstProducts I want it to repopulate lstAss with those three columns all parsed. – Todd Aug 15 '22 at 12:53

1 Answers1

0

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
Todd
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 27 '22 at 05:02