我如何从列表框中删除多个项目? [英] how i can remove more than one items from list box??

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

问题描述

如何从列表框中删除多个项目?
我想我应该使用选定的索引,但不知道如何使用它们!
我将选择模式更改为多扩展.
你能帮我吗?
谢谢.

How can I remove more than one item from a list box?
I think I should use selected indices but don''t know how to use them!
I changed the selection mode to multi extended.
Can you help me please?
Thanks.

推荐答案

你好roham_06,

首先,将选择模式"属性设置为多扩展".
Hi roham_06,

First you set Selection mode property to Multi Extended.
for(int nCount=0;nCount < listbox1.SelectedItems.Count;nCount++)
  {
    listbox1.Items.Remove(listbox1.SelectedItems[nCount].ToString());
    nCount--;
  }


在任何事件中进行编码

谢谢,
T.Saravanan;)


Give the Coding in any Event

Thanks,
T.Saravanan ;)


在删除处理程序"中:

In the ''delete handler'':

Object [] a = new Object[listBox1.SelectedItems.Count];
listBox1.SelectedItems.CopyTo(a, 0);
foreach (Object obj in a)
  listBox1.Items.Remove(obj);



请注意,我也是C#新手:也许有更好的方法来完成任务.
:)



Please note, I''m a C# newbie too: maybe there are better ways to accomplish the task.
:)


这篇关于我如何从列表框中删除多个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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