本文主要是介绍SearchLookUpEdit和 GridLookUpEdit,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基础数据:
public class Product{public int Id { get; set; }public string Model { get; set; }public string Name { get; set; }}public class Entility {private static string GetChar(int number){string[] array = new string[] { "A","B","C","D","E","F","G","H","I"};string result = array[number % 9];return result;}private static string GetName(int number){string[] array = {"Unitch数据采集器","MS扫描枪","105SL","TSC","PH880","MS320便携式打印机","PA700","DSX800电脑","HP打印机"};string result = array[number % 9];return result;}public static List<Product> GetProductList() {List<Product> list = new List<Product>();for (int i = 0; i < 200; i++){Product product = new Product() {Id=100+i,Model=GetChar(i)+i.ToString()+"DLJ",Name=GetName(i)+i.ToString()};list.Add(product);}return list;}
一.SearchLookUpEdit控件使用: 感觉此控件是否高大上。
数据绑定 和 在前面添加行号索引
private void Form3_Load(object sender, EventArgs e){List<Product> list = Entility.GetProductList();searchLookUpEdit1.Properties.DataSource = list;searchLookUpEdit1.Properties.DisplayMember = "code";searchLookUpEdit1.Properties.ValueMember = "code";searchLookUpEdit1.Properties.NullText = @"请选择";}private void searchLookUpEdit1View_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e){if (e.RowHandle >= 0 && e.Info.IsRowIndicator){e.Info.DisplayText = (e.RowHandle + 1).ToString();}}
添加数据列:
简单属性:
//双击显示下拉列表searchLookUpEdit1.Properties.ShowDropDown = ShowDropDown.DoubleClick;searchLookUpEdit1.Properties.ImmediatePopup = true;//显示下拉列表searchLookUpEdit1.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;//此控件不允许输入searchLookUpEdit1.Properties.NullText = "";//清空默认值二.GridLookUpEdit控件简单使用 效果:
数据绑定:
List<Product> list = Entility.GetProductList();gridLookUpEdit1.Properties.DataSource = list;
添加显示的数据列:并进行数据绑定 设置列的宽度
GridLoolUpEdit 默认 是根据 DisplayMember 绑定的字段 进行模糊筛选。
设置根据多列筛选功能:
private void FilterLookup(object sender){GridLookUpEdit edit = sender as GridLookUpEdit;GridView gridView = edit.Properties.View as GridView;FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);BinaryOperator op1 = new BinaryOperator("Id", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);BinaryOperator op2 = new BinaryOperator("Model", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);BinaryOperator op3 = new BinaryOperator("Name", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);string filterCondition = new GroupOperator(GroupOperatorType.Or, new CriteriaOperator[] { op1, op2,op3 }).ToString();fi.SetValue(gridView, filterCondition);MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);mi.Invoke(gridView, null);}private void gridLookUpEdit1_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e){BeginInvoke(new MethodInvoker(delegate(){FilterLookup(sender);}));}对筛选的列 显示行号
private void gridLookUpEdit1View_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e){if (e.Info.IsRowIndicator && e.RowHandle >= 0){e.Info.DisplayText = (e.RowHandle + 1).ToString();}}一些简单的属性设置:
//双击显示下拉列表gridLookUpEdit1.Properties.ShowDropDown = ShowDropDown.DoubleClick;gridLookUpEdit1.Properties.ImmediatePopup = true;//显示下拉列表gridLookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;//允许输入gridLookUpEdit1.Properties.NullText = "";//清空默认值设置下拉列表宽度
这篇关于SearchLookUpEdit和 GridLookUpEdit的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!