How to Create an Autocomplete Textbox in CSharp

In this tutorial, we will learn how to create an auto complete textbox using C# Windows Form Application. This is a very easy task to create a simple program and also you could use this part of a program to integrate in your existing system. So, Let us start!

First, create a new project, (remember we’re going to use the csharp form application not vb), then Add 1 Textbox and 1 Label, and then change the text property to Auto Complete Textbox.


Finish product will be like this:


Go to Code Editor and type the code below:

using System;
using System.Windows.Forms;
namespace TutorialCollectionCSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
      // function that you can call when you run the program
        private void autocomplete()
        {
            TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            TextBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
      //List of Fruits, you can add a fruits here
            TextBox1.AutoCompleteCustomSource.AddRange(new string[] {"Lemon", "Orange", "Apple", "Grapes", "Banana"});
        }

        private void frmAutoComplete_Load(object sender, EventArgs e)
        {
            autocomplete();
        }
    }
}

The final output:



How to Create an Autocomplete Textbox in CSharp How to Create an Autocomplete Textbox in CSharp Reviewed by code-dev on 10:43 AM Rating: 5

No comments:

Powered by Blogger.