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;
namespace X.WinFormsApp
{
/// <summary>
/// 输入查询的 Name 过滤显示
/// </summary>
public partial class X200906101045 : Form
{
private TextBox fInput;
private DataGridView fDataGridView;
private BindingSource fBindingSource;
#region " Employee "
private DataSet fEmployee;
public DataSet Employee
{
get
{
if (fEmployee == null)
{
fEmployee = new DataSet();
fEmployee.Tables.Add(new DataTable("Employee"));
fEmployee.Tables[0].Columns.Add(new DataColumn("EmployeeKey", typeof(Int32)));
fEmployee.Tables[0].Columns.Add(new DataColumn("Name", typeof(String)));
fEmployee.Tables[0].Columns.Add(new DataColumn("ModifyDate", typeof(DateTime)));
fEmployee.Tables[0].Rows.Add(new object[] { 1, "John", DateTime.Now });
fEmployee.Tables[0].Rows.Add(new object[] { 2, "Tomi", DateTime.Now });
fEmployee.Tables[0].Rows.Add(new object[] { 3, "X.XY", DateTime.Now });
fEmployee.Tables[0].Rows.Add(new object[] { 4, "Sam", DateTime.Now });
fEmployee.Tables[0].Rows.Add(new object[] { 5, "Mary", DateTime.Now });
fEmployee.Tables[0].Rows.Add(new object[] { 6, "Chirs", DateTime.Now });
}
return fEmployee;
}
}
#endregion
public X200906101045()
{
InitializeComponent();
this.InitControl();
}
private void InitControl()
{
fInput = new TextBox();
fInput.Location = new Point(10, 10);
fInput.KeyUp += new KeyEventHandler(fInput_KeyUp);
fDataGridView = new DataGridView();
fDataGridView.Location = new Point(10, 40);
fDataGridView.Size = new Size(300,300);
fBindingSource = new BindingSource(this.Employee, "Employee");
fDataGridView.DataSource = fBindingSource;
this.Controls.Add(fInput);
this.Controls.Add(fDataGridView);
}
void fInput_KeyUp(object sender, KeyEventArgs e)
{
this.fBindingSource.Filter = string.Format("Name LIKE '%{0}%'", this.fInput.Text);
}
}
}
知识改变命运,奋斗成就人生!