开发者

Getting Data from WinForms ListView Control

开发者 https://www.devze.com 2022-12-23 19:23 出处:网络
I need to retrieve my data from a ListView control set up in Details mode with 5 columns. I tried using this code:

I need to retrieve my data from a ListView control set up in Details mode with 5 columns.

I tried using this code:

MessageBox.Show(ManageList.SelectedItems(0).Text) 

And it works, but only for the first selected item (item 0). If I try this:

MessageBox.Show(ManageList.SelectedItems(2).Text)

I get this error:开发者_开发百科

InvalidArgument=Value of '2' is not valid for 'index'. Parameter name: index

I have no clue how I can fix this, any help?

Edit: Sorry, should have said, I'm using Windows.Forms :)


Right, from what I've tested:

Private Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
    For index As Integer = 0 To Me.listView1.SelectedItems.Count - 1
        MessageBox.Show(Me.listView1.SelectedItems(index).Text)
    Next
End Sub

(items added like this:)

For i As Integer = 0 To 99
    Me.listView1.Items.Add(String.Format("test{0}", i))
Next

It just works.

So are you sure you have selected more than 1 item? Could you please show us more code? :)

0

精彩评论

暂无评论...
验证码 换一张
取 消