删除listbox1前面项目中的特定字符? C # [英] Removing a specific character in front items of listbox1? C #

查看:134
本文介绍了删除listbox1前面项目中的特定字符? C #的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是用于删除listBox1前面所选项目中特定字符的代码,它可以正常工作。但是这个代码只删除了一个项目前面的特定字符。

如果我选择多个项目,我必须多次重复此操作。

我想如果我选择多个项目,一次移动我删除了每个项目前面的所有特定字符。请帮忙。谢谢。



我的尝试:



This is below the code for removing a specific character in front selected items of listBox1, and it works. But this code removing a specific character in front of only one item.
If I select multiple items, I have to repeat this operation several times.
I would like if I select multiple items, that with one move I removed all the specific characters in front each item. Please help. Thanks.

What I have tried:

 private void RemoveChar()
{
	int idx = listBox1.SelectedIndex;
	string sText = (string)listBox1.SelectedItem;

	if (sText.StartsWith("#"))
	{      
	 listBox1.Items[idx] = sText.Substring(1, sText.Length - 1).TrimStart();               
	}
}

推荐答案

看看使用 ListBox.SelectedItems属性(System.Windows.Forms) [ ^ ]而不是SelectedItem - 后者只返回单个项目,即使选择了多个项目。
Look at using the ListBox.SelectedItems Property (System.Windows.Forms)[^] instead of SelectedItem - the latter only ever returns a single item, even if multiple items are selected.


这篇关于删除listbox1前面项目中的特定字符? C #的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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