Category >
WINFORMS
|| Published on :
Thursday, July 24, 2014 || Views:
15336
||
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
OR
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;
3
4 namespace AutoComplete_feature
5 {
6 public partial class Form1 : Form
7 {
8 public Form1()
9 {
10 InitializeComponent();
11 }
12
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("www.sourcecodehub.com");
19 }
20 }
21
22 private void button1_Click(object sender, EventArgs e)
23 {
24 textBox2.AutoCompleteCustomSource.Add(textBox1.Text.ToString());
25 textBox1.Clear();
26 }
27 }
28 }
29
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