【原创】C# Dev用户自定义组件,自动下拉弹框表格过滤数据组件ucMyLookUpEdit
【原创】C# Dev用户自定义组件,自动下拉弹框表格过滤数据组件ucMyLookUpEdit
ucMyLookUpEdit组件介绍
ucMyLookUpEdit组件介绍
ucMyLookUpEdit用户自定义组件支持输入内容自动下拉弹框,表格自动过滤数据等功能,方便用户快速筛选数据并录入系统,该组件实现比较复杂,已成功应用在一套大型系统,功能成熟稳定。
ucMyLookUpEdit组件继承PopupContainerEdit,绑定KeyDown、EditValueChanged、Validating三个重要事件。
ucMyLookUpEdit组件继承PopupContainerEdit,绑定KeyDown、EditValueChanged、Validating三个重要事件。
KeyDown:用于捕获用户按键,按向下键Keys.Down弹出下拉窗体并设置光标,跳转到下拉窗体中。按回车键Keys.Enter,执行确认选择操作。
扫一扫加微信
Validating:用于校验输入文本是否存在。
EditValueChanged:用户输入资料,自动过滤数据。
客户系统使用案例:
使用方法,在加载窗体时设置表格过滤控件的数据源:
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
功能测试:
VS2017解决方案:
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网