You need to add these things to your project first of all
- Three buttons (add,show,clear)
- Listbox
- Textbox
After that time to code , just double click on button add which is button1 for me
//checking textbox1 for empty values or else add the values to listbox if(textBox1.Text == string.Empty) { MessageBox.Show("Come on enter some text", "Textbox empty"); } else { listBox1.Items.Add(textBox1.Text); textBox1.Text = ""; }Then go for show button
//checking for null values in listbox else display the message box lalalaalal if(listBox1.SelectedItem == null) { MessageBox.Show("select an item buddy", "select item"); } else { MessageBox.Show(listBox1.SelectedItem.ToString()); }Finally clear button
//clearing the listbox items and setting textbox1 value to empty listBox1.Items.Clear(); textBox1.Text = string.Empty;
Now all the parts are over, Full source below
private void button1_Click(object sender, EventArgs e) { //checking textbox1 for empty values or else add the values to listbox if(textBox1.Text == string.Empty) { MessageBox.Show("Come on enter some text", "Textbox empty"); } else { listBox1.Items.Add(textBox1.Text); textBox1.Text = ""; } } private void button2_Click(object sender, EventArgs e) { //checking for null values in listbox else display the message box lalalaalal if(listBox1.SelectedItem == null) { MessageBox.Show("select an item buddy", "select item"); } else { MessageBox.Show(listBox1.SelectedItem.ToString()); } } private void button3_Click(object sender, EventArgs e) { //clearing the listbox items and setting textbox1 value to empty listBox1.Items.Clear(); textBox1.Text = string.Empty; }i hope it was somehow helpful , thank you
3 comments
More Listbox operations http://csharp.net-informations.com/gui/cs-listbox.htm c# Listbox
ReplyPatter
Sekolah Blogger Indonesia
ReplySekolah Adsense
Sekolah Wordpress
Sekolah Blogger
Sekolah Hosting
Sekolah SEO
Forum Anime Indonesia 1212bhb
csharp coding examples
ReplyPost a Comment
Note: Only a member of this blog may post a comment.