C#中TextBox实现输入提示功能的方法
时间:2020-10-27 12:16:06|栏目:.NET代码|点击: 次
本文实例讲述了C#中TextBox实现输入提示功能的方法。分享给大家供大家参考。具体如下:
设置TextBox的AutoCompleteSource的属性为CustomSource,设置TextBox的AutoCompleteMode属性为SuggestAppend。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using WindowsApplication7.DataSet1TableAdapters; namespace WindowsApplication7 { public partial class Form1 : Form { DataSet1 ds = new DataSet1(); CustomersTableAdapter adpter = new CustomersTableAdapter(); public Form1() { InitializeComponent(); } private void BuildAutoCompleteList() { AutoCompleteStringCollection filterVals = new AutoCompleteStringCollection(); foreach (DataRow dr in ds.Customers) { filterVals.Add(dr["CompanyName"].ToString()); } txtCompanyName.AutoCompleteCustomSource = filterVals; } private void Form1_Load(object sender, EventArgs e) { adpter.Fill(ds.Customers); BuildAutoCompleteList(); } } }
希望本文所述对大家的C#程序设计有所帮助。
栏 目:.NET代码
下一篇:C#实现只运行单个实例应用程序的方法(使用VB.Net的IsSingleInstance)
本文地址:http://www.codeinn.net/misctech/16227.html