简体   繁体   English

循环浏览列表视图中的选定项目并从具有逗号分隔子项的子项填充另一个列表视图

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

I have a listview called lstProducts.我有一个名为 lstProducts 的列表视图。 The user selects an item in lstProducts to populate various objects in a form.用户在 lstProducts 中选择一个项目来填充表单中的各种对象。 Three of the subitems are comma delimited strings that must be parsed to populate lstAss.其中三个子项是逗号分隔的字符串,必须对其进行解析以填充 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 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:我的代码 lstAss 目前填充如下:

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.通过错误处理程序保证输入 lstProducts 的数据的完整性。 There is a matching subitem in col6, col10, & col11. col6、col10 和 col11 中有一个匹配的子项。

I solved this.我解决了这个问题。 I simply combined the 3 subitems into 1 comma delimited string and parsed it back into the originating listview.我只是将 3 个子项组合成 1 个逗号分隔的字符串,然后将其解析回原始列表视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM