欢迎来到天天文库
浏览记录
ID:12365447
大小:72.50 KB
页数:3页
时间:2018-07-16
《listbox重复项检测》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceEx067{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbtn_add_Click(ob
2、jectsender,EventArgse){if(txt_add.Text=="")//文本框为空{MessageBox.Show("添加的内容不能为空!");txt_add.Focus();//获取焦点}else{if(listBox1.Items.Count>0)//判断列表框中是否有项{//循环比较是否有重复项,有则放弃添加for(inti=0;i3、geBox.Show("列表框中已有相同项,不能添加!");//提示信息txt_add.Text="";//清空文本框txt_add.Focus();return;}}listBox1.Items.Add(txt_add.Text.ToString());//添加项txt_add.Text="";}else{listBox1.Items.Add(txt_add.Text.ToString());//将文本框中的数据添加到列表框txt_add.Text="";}}}}}
3、geBox.Show("列表框中已有相同项,不能添加!");//提示信息txt_add.Text="";//清空文本框txt_add.Focus();return;}}listBox1.Items.Add(txt_add.Text.ToString());//添加项txt_add.Text="";}else{listBox1.Items.Add(txt_add.Text.ToString());//将文本框中的数据添加到列表框txt_add.Text="";}}}}}
此文档下载收益归作者所有