[英]dividing listbox items into two parts and pasting them into two listbox
so the code i ma trying to run is: 所以我想运行的代码是:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim size2 As Integer = ListBox1.Items.Count / 2
Dim size1 As Integer = ListBox1.Items.Count - size2
ListBox2.Items.AddRange(ListBox1.Items.GetRange(0, size1))
ListBox3.Items.AddRange(ListBox1.Items.GetRange(size1, size2))
End Sub
i have imported System.Linq but error occers getrange is not a member of listbox.objectcollection 我已经导入了System.Linq,但错误发生率getrange不是listbox.objectcollection的成员
There's no such thing as a GetRange()
extension in Linq. Linq中没有
GetRange()
扩展这样的东西。 The List(Of T)
class has such a method , however. 但是,
List(Of T)
类具有这种方法 。 So you could use the Cast(Of TResult)
extension to convert the collection into an IEnumerable(Of T)
, then use the ToList()
extension to convert that into a List(Of T)
: 因此,您可以使用
Cast(Of TResult)
扩展将集合转换为IEnumerable(Of T)
,然后使用ToList()
扩展将其转换为List(Of T)
:
Dim ItemsList As List(Of Object) = ListBox1.Items.Cast(Of Object).ToList()
ListBox2.Items.AddRange(ItemsList.GetRange(0, size1))
ListBox3.Items.AddRange(ItemsList.GetRange(size1, size2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.