autocomplete textbox in windows applications? [Resolved]

Posted by Harikrishna.veluru under C# on 12/20/2011 | Points: 10 | Views : 3305 | Status : [Member] | Replies : 1
Hi,

i want to know how to create the autocomplete textbox in windows applications?.please do the needful.


Regards,
Hari.

best,
hari



Responses

Posted by: Sudheep.grandhe on: 12/20/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
public partial class AuthenticationForm : Form
{
public string strConnection = ("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

private void LoginForm_Load(object sender, EventArgs e)
{
txt_username.Focus();
RePaint();
SqlDataReader dReader;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = strConnection;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select distinct [UserName] from [tbl_login] order by [UserName] asc";
conn.Open();
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader["UserName"].ToString());
}
else
{
MessageBox.Show("Data Not Found");

}
dReader.Close();
txt_username.AutoCompleteMode = AutoCompleteMode.Suggest;
txt_username.AutoCompleteSource = AutoCompleteSource.CustomSource;
txt_username.AutoCompleteCustomSource = namesCollection;
}
}
 Download source file

Best,
Sudheep.

Harikrishna.veluru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response