标签:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CommonControl
{
public partial class SC_ComBox : UserControl
{
public SC_ComBox()
{
InitializeComponent();
}
#region Properties
private DataTable dt;
public DataTable DT
{
get { return dt;}
set { dt = value; }
}
private string displayMember;
public string DisplayMember
{
get { return displayMember; }
set { displayMember = value; }
}
private string valueMember;
public string ValueMember
{
get { return valueMember; }
set { valueMember = value; }
}
#endregion
private void SC_ComBox_TextUpdate(object sender, EventArgs e)
{
CBload();
}
public void CBload()
{
string defaulttxt = this.comboBox1.Text;
DataView dv = dt.DefaultView;
if (!string.IsNullOrEmpty(this.comboBox1.Text))
dv.RowFilter = DisplayMember + " like ‘%" + this.comboBox1.Text + "%‘";
DataTable dtnew = dv.ToTable();
this.comboBox1.DataSource = dtnew;
this.comboBox1.DisplayMember = displayMember;
this.comboBox1.ValueMember = valueMember;
this.comboBox1.Text = defaulttxt;
this.comboBox1.DroppedDown = true;
this.comboBox1.SelectionStart = defaulttxt.Length;//光标位置在右边
}
private void comboBox1_MouseClick(object sender, MouseEventArgs e)
{
CBload();
}
}
}
可输入的模糊搜索ComBox控件
标签:
原文地址:http://www.cnblogs.com/sulong/p/4900234.html