Method of Implementing Input Prompt Function by TextBox in C
- 2021-06-28 13:41:45
- OfStack
This article gives an example of how TextBox in C#implements the function of input prompt.Share it for your reference.Specifically as follows:
Set AutoCompleteSource for TextBox to CustomSource and AutoCompleteMode for TextBox to 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();
}
}
}
I hope that the description in this paper will be helpful to everyone's C#program design.