Link to home
Start Free TrialLog in
Avatar of rajputamitd
rajputamitd

asked on

Clear ListBOx Item

I have a ListBox,in which I set a text like "Click For States".Now I want to clear when I add states to this ListBox.Which method is there to retrieve the Text in the ListBox and to clear that.

I want to clear that message when I add states in that.When that ListBox contains"Click for states" and when I am adding states in it,the message should be cleared.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Kamaraj Subramanian
Kamaraj Subramanian
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hope this helps
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "Click for states";
            
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.Equals(""))
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text=""
            }
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }
 
        private void textBox1_MouseEnter(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
    }
}

Open in new window

Avatar of rajputamitd
rajputamitd

ASKER

Ya I do understand what u want to say.But is there any other way trrough I can achieve the same.
Avatar of Obadiah Christopher
lstName.Items.Clear();

Is this what you are looking for?
Thanks for you help guys.Problem is solved.