简体   繁体   English

如何遍历列表视图并将主项和子项文本分配到迭代按钮上

[英]How to iterate through a listview and assign the main item and subitems texts onto iterated buttons

I'm trying to grab the texts of each row of a ListView and assiging it to the iterated tiles/buttons. 我正在尝试抓取ListView的每一行的文本并将其分配给迭代的tile /按钮。 The code I written unfortunately take only the last row and prints it onto all the iterated Tiles. 不幸的是,我写的代码只占用最后一行并将其打印到所有迭代的Tiles上。 (the Tiles are DevExpress - third party comps. by the way. but thats not the focus here) (Tiles是DevExpress - 顺便说一句第三方补偿。但这不是重点)

For example. 例如。 The listview contains the following two rows (it may be more); 列表视图包含以下两行(可能更多);

Name | Country | City
---------------------------
Sam  |  Japan  | Tokyo
Dexter | Italy | Rome

thus what I seek is the ability to print onto the iterated tiles/buttons in this way: 因此我所寻求的是以这种方式打印到迭代的瓷砖/按钮上的能力:

FIRST TILE's TEXT: 第一个文章的文字:
Sam 山姆
Japan Tokyo 日本东京

SECOND TILE's TEXT: Dexter 第二篇文章的文字:德克斯特
Italy 意大利
Rome 罗马

This is my code: 这是我的代码:

Dim strTileInfo As String = Nothing

    For Each tile As TileItem In TheTileControl.Items 'My iteration code through the tiles/buttons

        strTileInfo = Nothing
        tile.Text = Nothing

        'My attempt to assign each row of the ListView main item and subitem texts 
        'i.e. Each row to each button
        For i = 0 To ListView.Items.Count - 1
            strTileInfo = ListView.Items(i).Text & vbCrlf & ListView.Items(i).SubItems(1).Text
            tile.Text = strTileInfo
        Next

    Next

I will be very grateful for your assistance. 我将非常感谢你的帮助。 Thank you. 谢谢。

The code take only the last row and prints it in all the iterated Tiles, because for each Tile you cross the ListView to the last element, and the latter is assigned under. 代码只占用最后一行并将其打印在所有迭代的Tiles中,因为对于每个Tile,您将ListView交叉到最后一个元素,后者在下面分配。 Try this code : 试试这段代码:

Dim strTileInfo As String = Nothing

Dim i As Integer = 0
For Each tile As TileItem In TheTileControl.Items
    strTileInfo = Nothing
    tile.Text = Nothing

    If i < ListView.Items.Count Then
        strTileInfo = ListView.Items(i).Text & vbCrLf & ListView.Items(i).SubItems(1).Text
        tile.Text = strTileInfo
        i += 1
    End If

Next

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

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