【问题标题】:Visual Basic 2010 Listbox ErrorVisual Basic 2010 列表框错误
【发布时间】:2012-10-15 05:10:34
【问题描述】:

这个错误是什么意思?不好意思这是我第一次使用Visual Basic 2010,我不熟悉这种错误,我用它来选择列表框中的所有文件并试图移动或复制到其他形式的另一个列表框。

错误 1 ​​'ToArray' 不是 'System.Windows.Forms.ListBox.ObjectCollection'。

这是我使用的代码。

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) 处理 Button1.Click

如果 RadioButton1.Checked Then

        Dim itemsToMove = ListBox1.Items.ToArray()
        For Each item In itemsToMove
            Form2.lstP.Items.Add(item)
            ListBox1.Items.Remove(item)
        Next
        Form2.Show()
    End If

End Sub

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: visual-studio-2010


    【解决方案1】:

    错误的意思是Listbox.ObjectCollection 没有名为ToArray 的方法或属性。所以,你不能在这个集合上调用 ToArray。目前尚不清楚您为什么要这样做。

    【讨论】:

      【解决方案2】:

      无需将 ListBox 转换为数组。如果您需要知道列表中的项目数,可以执行以下操作

          Dim itemsToMove As Integer = ListBox1.Items.Count
      

      否则,不需要这行代码 Dim itemsToMove = ListBox1.Items.ToArray() 。你可以简单地使用

          For Each item In ListBox1
              Form2.lstP.Items.Add(item)
              ListBox1.Items.Remove(item)
          Next
      

      【讨论】:

        猜你喜欢
        • 2012-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-29
        • 2015-06-26
        • 1970-01-01
        • 2011-11-22
        相关资源
        最近更新 更多