【原创】C# Dev用户自定义组件,自动下拉弹框表格过滤数据组件ucMyLookUpEdit
![](http://www.csframework.com/images/article-type5.gif)
![【原创】C# DevExpress自动下拉弹框表格过滤数据组件ucMyLookUpEdit](http://www.csframework.com/images/seo/csframework-seo-cshart%E5%AE%9E%E4%BE%8B%E6%BA%90%E7%A0%81.jpg)
ucMyLookUpEdit组件介绍
ucMyLookUpEdit用户自定义组件支持输入内容自动下拉弹框,表格自动过滤数据等功能,方便用户快速筛选数据并录入系统,该组件实现比较复杂,已成功应用在一套大型系统,功能成熟稳定。
ucMyLookUpEdit组件继承PopupContainerEdit,绑定KeyDown、EditValueChanged、Validating三个重要事件。
ucMyLookUpEdit组件继承PopupContainerEdit,绑定KeyDown、EditValueChanged、Validating三个重要事件。
KeyDown:用于捕获用户按键,按向下键Keys.Down弹出下拉窗体并设置光标,跳转到下拉窗体中。按回车键Keys.Enter,执行确认选择操作。
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件5](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件5.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件6](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件6.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件1](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件1.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件2](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件2.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件3](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件3.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件4](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件4.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件7](http://www.csframework.com/upload/image/DevExpress%E8%87%AA%E5%8A%A8%E4%B8%8B%E6%8B%89%E5%BC%B9%E6%A1%86%E8%A1%A8%E6%A0%BC%E8%BF%87%E6%BB%A4%E6%95%B0%E6%8D%AE%E7%BB%84%E4%BB%B67.png)
![C/S框架网|原创精神.创造价值.打造精品](http://www.csframework.com/images/our03.gif)
扫一扫加微信
![C/S框架网|原创作品.质量保障.竭诚为您服务](http://www.csframework.com/images/CS框架网提供高效优质服务.jpg)
Validating:用于校验输入文本是否存在。
EditValueChanged:用户输入资料,自动过滤数据。
客户系统使用案例:
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件5](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件5.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件6](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件6.png)
使用方法,在加载窗体时设置表格过滤控件的数据源:
C# Code:
private void Form1_Load(object sender, EventArgs e)
{
//客户资料筛选组件
txtCustomer.InitControl(new MyLookUpCustomer());
txtCustomer.IsBoundDataField = false;
//供应商资料筛选组件
txtSupplier.InitControl(new MyLookUpSupplier());
txtSupplier.IsBoundDataField = false;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
//客户资料筛选组件
txtCustomer.InitControl(new MyLookUpCustomer());
txtCustomer.IsBoundDataField = false;
//供应商资料筛选组件
txtSupplier.InitControl(new MyLookUpSupplier());
txtSupplier.IsBoundDataField = false;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
客户资料数据源:
C# Code:
/// <summary>
/// 客户资料数据源
/// </summary>
public class MyLookUpCustomer : IMyLookUpDataSource
{
private object _LookUpData = null;
private string FILTER = "CustomerCode LIKE '%{0}%' OR CustomerName LIKE '%{1}%' OR ContactTel LIKE '%{2}%'";
public string DisplayMember { get { return "CustomerName"; } }
public string KeyMember { get { return "CustomerCode"; } }
private bool _MultiSelect = false;
public bool MultiSelect
{
get { return _MultiSelect; }
set { _MultiSelect = value; }
}
public object LookUpData
{
get
{
if (_LookUpData == null) _LookUpData = DemoData.Customers;
return _LookUpData;
}
set { _LookUpData = value; }
}
public object GetFiltedData(string searchContent)
{
if (_LookUpData != null)
{
(_LookUpData as DataTable).DefaultView.RowFilter = String.Format(FILTER, searchContent, searchContent, searchContent);
return _LookUpData;
}
else
{
return null;
}
}
/// <summary>
/// 初始化下拉表格的列对象,设置标题宽度
/// </summary>
/// <param name="popup"></param>
/// <param name="gridView"></param>
public void InitGridUI(PopupContainerControl popup, GridView gridView)
{
MyLookUpTool.SetField(gridView, "CustomerCode", "CustomerName", "ContactTel", "", "");
MyLookUpTool.SetCaption(gridView, "客户编码", "客户名称", "联系电话", "", "");
MyLookUpTool.SetWidth(gridView, 100, 250, 100, 0, 0);
MyLookUpTool.SetWidth(popup, gridView);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// 客户资料数据源
/// </summary>
public class MyLookUpCustomer : IMyLookUpDataSource
{
private object _LookUpData = null;
private string FILTER = "CustomerCode LIKE '%{0}%' OR CustomerName LIKE '%{1}%' OR ContactTel LIKE '%{2}%'";
public string DisplayMember { get { return "CustomerName"; } }
public string KeyMember { get { return "CustomerCode"; } }
private bool _MultiSelect = false;
public bool MultiSelect
{
get { return _MultiSelect; }
set { _MultiSelect = value; }
}
public object LookUpData
{
get
{
if (_LookUpData == null) _LookUpData = DemoData.Customers;
return _LookUpData;
}
set { _LookUpData = value; }
}
public object GetFiltedData(string searchContent)
{
if (_LookUpData != null)
{
(_LookUpData as DataTable).DefaultView.RowFilter = String.Format(FILTER, searchContent, searchContent, searchContent);
return _LookUpData;
}
else
{
return null;
}
}
/// <summary>
/// 初始化下拉表格的列对象,设置标题宽度
/// </summary>
/// <param name="popup"></param>
/// <param name="gridView"></param>
public void InitGridUI(PopupContainerControl popup, GridView gridView)
{
MyLookUpTool.SetField(gridView, "CustomerCode", "CustomerName", "ContactTel", "", "");
MyLookUpTool.SetCaption(gridView, "客户编码", "客户名称", "联系电话", "", "");
MyLookUpTool.SetWidth(gridView, 100, 250, 100, 0, 0);
MyLookUpTool.SetWidth(popup, gridView);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
供应商数据源:
C# Code:
/// <summary>
/// 供应商资料数据源
/// </summary>
public class MyLookUpSupplier : IMyLookUpDataSource
{
private List<DemoData.MySupplier> _LookUpData = null;
public string DisplayMember { get { return "Name"; } }
public string KeyMember { get { return "Code"; } }
private bool _MultiSelect = false;
public bool MultiSelect
{
get { return _MultiSelect; }
set { _MultiSelect = value; }
}
public object LookUpData
{
get
{
if (_LookUpData == null) _LookUpData = DemoData.Suppliers;
return _LookUpData;
}
set { _LookUpData = value as List<DemoData.MySupplier>; }
}
public object GetFiltedData(string searchContent)
{
if (_LookUpData != null)
{
List<DemoData.MySupplier> source = _LookUpData as List<DemoData.MySupplier>;
//使用LINQ查询对象
List<DemoData.MySupplier> list = source.Where(
r => r.Code.Contains(searchContent) ||
r.Name.Contains(searchContent) ||
r.Tel.Contains(searchContent)).ToList();
return list;
}
else
{
return null;
}
}
/// <summary>
/// 初始化下拉表格的列对象,设置标题宽度
/// </summary>
/// <param name="popup"></param>
/// <param name="gridView"></param>
public void InitGridUI(PopupContainerControl popup, GridView gridView)
{
MyLookUpTool.SetField(gridView, "Code", "Name", "Tel", "", "");
MyLookUpTool.SetCaption(gridView, "编码", "名称", "电话", "", "");
MyLookUpTool.SetWidth(gridView, 100, 250, 100, 0, 0);
MyLookUpTool.SetWidth(popup, gridView);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// 供应商资料数据源
/// </summary>
public class MyLookUpSupplier : IMyLookUpDataSource
{
private List<DemoData.MySupplier> _LookUpData = null;
public string DisplayMember { get { return "Name"; } }
public string KeyMember { get { return "Code"; } }
private bool _MultiSelect = false;
public bool MultiSelect
{
get { return _MultiSelect; }
set { _MultiSelect = value; }
}
public object LookUpData
{
get
{
if (_LookUpData == null) _LookUpData = DemoData.Suppliers;
return _LookUpData;
}
set { _LookUpData = value as List<DemoData.MySupplier>; }
}
public object GetFiltedData(string searchContent)
{
if (_LookUpData != null)
{
List<DemoData.MySupplier> source = _LookUpData as List<DemoData.MySupplier>;
//使用LINQ查询对象
List<DemoData.MySupplier> list = source.Where(
r => r.Code.Contains(searchContent) ||
r.Name.Contains(searchContent) ||
r.Tel.Contains(searchContent)).ToList();
return list;
}
else
{
return null;
}
}
/// <summary>
/// 初始化下拉表格的列对象,设置标题宽度
/// </summary>
/// <param name="popup"></param>
/// <param name="gridView"></param>
public void InitGridUI(PopupContainerControl popup, GridView gridView)
{
MyLookUpTool.SetField(gridView, "Code", "Name", "Tel", "", "");
MyLookUpTool.SetCaption(gridView, "编码", "名称", "电话", "", "");
MyLookUpTool.SetWidth(gridView, 100, 250, 100, 0, 0);
MyLookUpTool.SetWidth(popup, gridView);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
ucMyLookUpEdit组件继承PopupContainerEdit组件
C# Code:
/// <summary>
/// C# DevExpress自动下拉弹框表格过滤数据组件
/// </summary>
public class ucMyLookUpEdit : PopupContainerEdit
{
private IMyLookUpDataSource _DataSource;
public IMyLookUpDataSource DataSource
{
get { return _DataSource; }
}
private Form _Owner = null;
private object _TmpData;
/// <summary>
/// 构造器
/// </summary>
public ucMyLookUpEdit()
{
_PopupControl = new ucMyLookUpEditPopup();
_PopupControl.OwnerEditor = this;
this.EditValueChanged += ucMyLookUpEdit_EditValueChanged;
this.Validating += new System.ComponentModel.CancelEventHandler(ucCustomerCombox_Validating);
this.Properties.TextEditStyle = TextEditStyles.Standard;
this.KeyDown += new System.Windows.Forms.KeyEventHandler(ucCustomerCombox_KeyDown);
}
//
//省略代码.....
//
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// C# DevExpress自动下拉弹框表格过滤数据组件
/// </summary>
public class ucMyLookUpEdit : PopupContainerEdit
{
private IMyLookUpDataSource _DataSource;
public IMyLookUpDataSource DataSource
{
get { return _DataSource; }
}
private Form _Owner = null;
private object _TmpData;
/// <summary>
/// 构造器
/// </summary>
public ucMyLookUpEdit()
{
_PopupControl = new ucMyLookUpEditPopup();
_PopupControl.OwnerEditor = this;
this.EditValueChanged += ucMyLookUpEdit_EditValueChanged;
this.Validating += new System.ComponentModel.CancelEventHandler(ucCustomerCombox_Validating);
this.Properties.TextEditStyle = TextEditStyles.Standard;
this.KeyDown += new System.Windows.Forms.KeyEventHandler(ucCustomerCombox_KeyDown);
}
//
//省略代码.....
//
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
功能测试:
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件1](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件1.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件2](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件2.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件3](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件3.png)
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件4](http://www.csframework.com/upload/image/DevExpress自动下拉弹框表格过滤数据组件4.png)
VS2017解决方案:
![贴图图片-DevExpress自动下拉弹框表格过滤数据组件7](http://www.csframework.com/upload/image/DevExpress%E8%87%AA%E5%8A%A8%E4%B8%8B%E6%8B%89%E5%BC%B9%E6%A1%86%E8%A1%A8%E6%A0%BC%E8%BF%87%E6%BB%A4%E6%95%B0%E6%8D%AE%E7%BB%84%E4%BB%B67.png)
![C/S框架网|原创精神.创造价值.打造精品](http://www.csframework.com/images/our03.gif)
扫一扫加微信
![C/S框架网作者微信](http://www.csframework.com/images/wechatcode.jpg)
![C/S框架网|原创作品.质量保障.竭诚为您服务](http://www.csframework.com/images/CS框架网提供高效优质服务.jpg)
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网