public void textBox5_xiala() { DataSet ds = SQl_yuji.ds_cinvname(); this.textBox5.AutoCompleteMode = AutoCompleteMode.SuggestAppend; this.textBox5.AutoCompleteSource = AutoCompleteSource.CustomSource; // DataTable table = new DataTable(); // table = ds.Tables[0]; ArrayList al = new ArrayList(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!al.Contains(ds.Tables[0].Rows[i]["cInvName"].ToString())) { al.Add(ds.Tables[0].Rows[i]["cInvName"].ToString()); } } AutoCompleteStringCollection ac = new AutoCompleteStringCollection(); string[] s = (string[])al.ToArray(typeof(string)); for (int i = 0; i < s.GetLength(0); i++) { ac.Add(s[i]); } this.textBox5.AutoCompleteCustomSource = ac;//设置该文本框的自动完成数据源 }
效果图