【问题标题】:ListBoxArray .GetIndex method not working properly.ListBoxArray .GetIndex 方法无法正常工作。
【发布时间】:2014-02-07 06:41:43
【问题描述】:

当我尝试使用从 ListBoxArray 获取列表框选定项的索引时 ListBoxArray.GetIndex 方法返回错误的索引号。

此列表框项目具有选择模式 multisimple。我需要最后一个选定项目的索引。

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: .net vb.net winforms c#-4.0


    【解决方案1】:

    试试这个:

    Dim item = ListBox1.SelectedItems(ListBox1.SelectedItems.Count - 1)
    

    它将返回您在列表中选择的项目的最后一项。

    找到最后一项后,您可以使用 FindIndex 在整个列表中获取它的索引。

    如果列表包含字符串,这里是一个示例:

     Dim ind As Integer = ListBox1.Items.Cast(Of String). _
            ToList().FindIndex(Function(x) x = item.ToString())
    

    如果您列出的对象是另一种类型,只需更改 Cast(of) 类型。

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 2021-12-29
      • 2014-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多