AutoComplete Feature in winform application using C Sharp

  WINFORMS   Thursday, July 24, 2014   11432 | No Comments Yet!!! | Not Downloaded Yet!!! | No Demo | Barkha Singh
 Tags: AutoComplete Feature  Winform Application  C Sharp  Winform Handy Trick and Tips  Winform Example 

In this article, I will explain you how can we use the AutoComplete Feature in winform application using C Sharp. For example I have created a winform application using c sharp from the Visual Studio. You can follow the given below steps to achieve the solution. For any graphical user interface, this may become very usefull feature that makes it easy for users to fill in applications or forms by suggesting them suitable words or phrases in appropriate text boxes.

So, while it may look like a tough job; it’s actually quite easy to use this feature. The text boxes in C Sharp contain an AutoCompleteMode which can be set to one of the three available choices i.e. Suggest , Append or SuggestAppend. Any choice would do but my favorite is the SuggestAppend.

This can be done through design mode using properties window for textBox1 and textBox2 as displayed in below figure


We can change properties of these textboxes thorugh code behind like :

                textBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                textBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;

Next we must set the AutoCompleteSource to CustomSource because we will supply the words or phrases to be suggested. The last step includes calling the AutoCompleteCustomSouce.Add() function with the required.


Full Code Behind Source Code

  1 using System;
  2 using System.Windows.Forms;
  4 namespace AutoComplete_feature
  5 {
  6     public partial class Form1 : Form
  7     {
  8         public Form1()
  9         {
 10             InitializeComponent();
 11         }
 13         private void Form1_Load(object sender, EventArgs e)
 14         {
 15             {
 16                 textBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
 17                 textBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;
 18                 textBox2.AutoCompleteCustomSource.Add("");
 19             }
 20         }
 22         private void button1_Click(object sender, EventArgs e)
 23         {
 24             textBox2.AutoCompleteCustomSource.Add(textBox1.Text.ToString());
 25             textBox1.Clear();
 26         }
 27     }
 28 }

Output in Running Mode


Hope you have enjoyed this step by step tutorial to learn how to AutoComplete Feature in winform application using C Sharp.

Download Source Codes

Post Comments

if you have some suggestion, question, request on AutoComplete Feature in winform application using C Sharp.

Please use the comment box to express your views.