如何获取列表框中每个选定项目的字符串(MultiSimple) [英] How to get string of each selected item in Listbox (MultiSimple)

查看:140
本文介绍了如何获取列表框中每个选定项目的字符串(MultiSimple)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个列表框,其中SelectionMode = MultiSimple,我想检查它们包含的字符串,以便对每个字符串进行相应的操作(请参见代码段).

到目前为止,我已经尝试过:

Hi there,

I''ve got a Listbox where SelectionMode = MultiSimple and I''d like to check the strings they contain to follow up with according actions (see Snippet) for each.

What I''ve tried so far:

For Each selecteditem As [Object] In ListBox1.SelectedItems
    If ListBox1.SelectedItem.ToString = "Text 1" Then
        Action 1
    ElseIf ListBox1.SelectedItem.ToString = "Text 2" Then
        Action 2
    ElseIf ListBox1.SelectedItem.ToString = "Text 3" Then
        Action 3
    End If
Next



问题:对于所选的每个项目执行For ... Next语句 (如果我选择3个项目,它将执行3次,如果我选择2个,则执行2次)时间等),但我认为iBlade.ListBox2.SelectedItem.ToString仅返回我选择的第一项.

如果选择文本1",文本2"和文本3",则文本1"的动作(动作1")将执行3次.如果我选择文本2"和文本3",则文本2"的动作(动作2")将重复两次,依此类推...

我想对动作2"和动作3"分别执行一次.但是我无法真正弄清楚.



The problem: While the For...Next Statement is executed for each item that is selected (If I select 3 items it''s executed 3 times, if I select 2 it''s executed 2 times, etc) but I think iBlade.ListBox2.SelectedItem.ToString only returns the first item I select.

If I select "Text 1", "Text 2" and "Text 3" the Action ("Action 1") for "Text 1" is executed three times. If I select "Text 2" and "Text 3" the Action ("Action 2") for "Text 2" is repeated two times and so on...

What I''d like to happen is for "Action 2" and "Action 3" each to be executed once. But I can''t really figure it out.

推荐答案

Sandeep Mewara试图告诉您使用selecteditem对象,而不是ListBox1.SelectedItems(LBitmCounter).在我的示例中,我将其替换为oItem
Sandeep Mewara was trying to tell you to use selecteditem object, not ListBox1.SelectedItems(LBitmCounter). In my example i replaced it with oItem
For Each oItem As [Object] In ListBox1.SelectedItems
    If oItem.ToString = "Text 1" Then
        Action 1
    ElseIf oItem.ToString = "Text 2" Then
        Action 2
    ElseIf oItem.ToString = "Text 3" Then
        Action 3
    End If
Next



了解有关选择案例 [



Learn about SELECT CASE[^] statement.


For LBitmCounter = 0 To ListBox1.SelectedItems.Count - 1
    If ListBox1.SelectedItems(LBitmCounter).ToString = "Text 1" Then
        Action 1
    ElseIf ListBox1.SelectedItems(LBitmCounter).ToString = "Text 2" Then
        Action 2
    ElseIf ListBox1.SelectedItems(LBitmCounter).ToString = "Text 3" Then
        Action 3
    End If
Next


这篇关于如何获取列表框中每个选定项目的字符串(MultiSimple)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆