|
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;
using DevExpress.XtraEditors.Controls;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable dt = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
try
{
BindData();
}
catch (Exception)
{
//TODO
}
}
/// <summary>
/// 给全局dt复制,这里可以是sql语句,得到table后循环table绑定数据到控件
/// </summary>
private void BindData()
{
dt.Columns.Add(new DataColumn("value", typeof(string)));
for (int i = 0; i < 100; i++)
{
DataRow dr = dt.NewRow();
dr["value"] = i.ToString();
dt.Rows.Add(dr);
this.comboBoxEdit1.Properties.Items.Add(i);//绑定数据到控件
}
this.lookUpEdit1.Properties.DataSource = dt;
this.lookUpEdit1.Properties.ValueMember = "value";
this.lookUpEdit1.Properties.DisplayMember = "value";
this.lookUpEdit1.Properties.ShowHeader = false;
}
private void comboBoxEdit1_KeyUp(object sender, KeyEventArgs e)
{
try
{
string str = comboBoxEdit1.Text.ToString();
//if (str == "")
// return;
comboBoxEdit1.Properties.Items.Clear();//无论有没有过滤,都要清空原来的值
string s = "value like '%" + str + "%'";
DataView v = dt.DefaultView;
v.RowFilter = s;
DataTable dtt = v.ToTable();
if (dtt.Rows.Count > 0)//如果输入的值过滤后有满足的值,则加载满足条件的值,否则加载全部
{
for (int i = 0; i < dtt.Rows.Count; i++)
{
this.comboBoxEdit1.Properties.Items.Add(dtt.Rows[i]["value"].ToString());
}
}
else
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBoxEdit1.Properties.Items.Add(dt.Rows[i]["value"].ToString());
}
}
}
catch (Exception)
{
//TODO
}
}
}
}
|