a1204773
a1204773

Reputation: 7043

C# textbox show previous written texts

For example if you go to facebook and press double click on the login textbox, then there are some Logins that previous someone wrote. Is there any way to make this dropdown of previous inputs on C# textbox? I don't want combobox.

Upvotes: 1

Views: 11755

Answers (1)

Habib
Habib

Reputation: 223207

See the TextBox.AutoCompleteMode and TextBox.AutoCompleteSource properties of the TextBox. You need to do something on the following lines:

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            autoComplete.Add(textBox1.Text);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            //auto.Add(textBox1.Text);
            textBox1.AutoCompleteCustomSource = autoComplete;
        }
    }
}

Check the following Tutorial: AutoComplete TextBox In WinForms Windows Forms Application

Upvotes: 7

Related Questions