不会从listbox1项中删除 [英] will not be deleting from listbox1 items

查看:66
本文介绍了不会从listbox1项中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我从list1移到list2时,它将正常工作.
但是,与此同时,它不会从list1中删除.

我的代码有什么问题.
请参见下面的代码.
-----------------

Hi,

When i move from list1 to list2, it will working fine.
but, meantime it will not be deleting from list1.

what is the problem in my code.
see code below.
-----------------

If lstTot.SelectedIndex > -1 Then
            Dim _value As String = lstTot.SelectedItem.Value
            Dim _text As String = lstTot.SelectedItem.Text
            Dim item As New ListItem()
            item.Text = _text
            item.Value = _value
            For Each li As ListItem In lstTot.Items
                If li.Selected = True Then
                    lstEx.Items.Add(li.Text)
                    lstTot.Items.Remove(li.Text)
                End If
            Next
        End If

推荐答案

执行循环后,再次绑定lstTot.希望能解决您的问题.您没有提到如何填充lstTot
After execution of the loop, bind lstTot once again. Hope that will resolve your problem. You didn''t mention how lstTot got populated


在Remove方法中,仅传递"li"代替"li.Text"
In Remove method pass only ''li'' in place of ''li.Text''


这不是从列表中删除项目的正确方法.您可能会遇到错误.

像这样尝试:
This is not a right way to remove items from list. You may get errors.

Try like this:
For Each obj As Object In lstTot.SelectedItems
    lstEx.Items.Add(obj)
Next
While lstTot.SelectedIndices.Count > 0
      lstTot.Items.RemoveAt(lstTot.SelectedIndices.Item(0))
End While


这篇关于不会从listbox1项中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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