- public void AddItem(string text,ListBox mylistbox)
- {
- try
- {
- bool isExists = false;
- foreach (ListItem item in mylistbox.Items)
- {
- if (item.Text == text)
- {
- isExists = true;
- break;
- }
- }
- if (!isExists)
- {
- mylistbox.Items.Add(text);
- }
- }
- catch { }
- }
LISTBOX不重复添加项
最新推荐文章于 2020-06-12 14:29:12 发布
本文介绍了一个实用的C#方法,该方法用于向ListBox中添加字符串项,并确保每个项的唯一性。通过遍历ListBox的Items集合检查目标文本是否已存在,如果不存在则添加,从而避免重复项。
1613

被折叠的 条评论
为什么被折叠?



