ASp.net

Saturday, September 12, 2015

AutoComplete Textbox in VB Net Use C#

1 comment:

  1. using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    Autocomplete();
    }

    private void Autocomplete()
    {
    try
    {
    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=I:\C3 soft\WindowsFormsApplication2\WindowsFormsApplication2\MTechSqlDatabase.mdf;Integrated Security=True;Connect Timeout=30");
    con.Open();
    string qry = string.Format("Select CustomerName From Customer");
    SqlCommand cmd = new SqlCommand(qry, con);
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds, "CustomerName");
    AutoCompleteStringCollection col = new AutoCompleteStringCollection();

    foreach (DataRow row in ds.Tables[0].Rows)
    {
    col.Add(row[0].ToString());
    }

    textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
    textBox1.AutoCompleteCustomSource = col;
    textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    con.Close();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }

    }
    }

    ReplyDelete

MM Online Express | Best product Review and Online Marketing site

MM Online Express | Best product Review and Online Marketing site