Combox AutoComplete
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; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (SqlConnection cn = new SqlConnection("資料庫連線字串")) { cn.Open(); using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = cn; cmd.CommandText = "SELECT 欄位一, 欄位二 FROM 資料表 "; using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); this.comboBox1.DisplayMember = "欄位一"; this.comboBox1.ValueMember = "欄位二"; this.comboBox1.DataSource = dt; comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; comboBox1.Focus(); } } } } } }