Textbox auto complete in windows application
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;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace WindowsForm_Autocomplete
{
public partial class Form1 : Form
{
AutoCompleteStringCollection namesCollection =new AutoCompleteStringCollection();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlDataReader dReader;
SqlConnection conn = new SqlConnection(@"Data Source=IGRID103\SHAREPOINT;Initial Catalog=Multilingual;Integrated Security=True");
//conn.ConnectionString = strConnection;
SqlCommand cmd = new SqlCommand("Select distinct [English] from [Languages] order by [English] asc", conn);
conn.Open();
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader["English"].ToString());
}
else
{
MessageBox.Show("Data not found");
}
dReader.Close();
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource = namesCollection;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
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;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace WindowsForm_Autocomplete
{
public partial class Form1 : Form
{
AutoCompleteStringCollection namesCollection =new AutoCompleteStringCollection();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlDataReader dReader;
SqlConnection conn = new SqlConnection(@"Data Source=IGRID103\SHAREPOINT;Initial Catalog=Multilingual;Integrated Security=True");
//conn.ConnectionString = strConnection;
SqlCommand cmd = new SqlCommand("Select distinct [English] from [Languages] order by [English] asc", conn);
conn.Open();
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader["English"].ToString());
}
else
{
MessageBox.Show("Data not found");
}
dReader.Close();
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource = namesCollection;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Result

No comments:
Post a Comment