DevExpress控件庫----LookUpEdit控件 和 GridLookUpEdit控件使用spa
一.LookUpEdit控件簡單使用: 下面是使用到的基礎數據code
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; } public static DataTable GetDataTable() { DataTable dt = new DataTable(); dt.Columns.Add("Id",typeof(System.Int32)); dt.Columns.Add("Model", typeof(System.String)); dt.Columns.Add("Name", typeof(System.String)); for (int i = 0; i < 200; i++) { DataRow dr = dt.NewRow(); dr["Id"] = 100 + i; dr["Model"] = GetChar(i) + i.ToString() + "DLJ"; dr["Name"] = GetName(i) + i.ToString(); dt.Rows.Add(dr); } return dt; } }
先看一下效果:blog
數據綁定: get
List<Product> list = Entility.GetProductList();
lookUpEdit1.Properties.DataSource = list;
添加顯示的列:找到屬性列表---添加要綁定的列。若是沒有添加列 根據屬性名稱 自動生成列
string
簡單屬性設置:it
//雙擊顯示下拉列表 lookUpEdit1.Properties.ShowDropDown = ShowDropDown.DoubleClick; lookUpEdit1.Properties.ImmediatePopup = true;//顯示下拉列表 lookUpEdit1.Properties.TextEditStyle = TextEditStyles.Standard;//容許輸入 lookUpEdit1.Properties.DropDownRows = 12;//默認顯示的行 lookUpEdit1.Properties.PopupWidth = 350;//設置寬帶 lookUpEdit1.Properties.NullText = "";//清空默認值
二.GridLookUpEdit控件簡單使用
效果:io
數據綁定:class
List<Product> list = Entility.GetProductList();
gridLookUpEdit1.Properties.DataSource = list;
添加顯示的數據列:並進行數據綁定 設置列的寬度基礎
GridLoolUpEdit 默認 是根據 DisplayMember 綁定的字段 進行模糊篩選。object
設置根據多列篩選功能:
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 = "";//清空默認值
設置下拉列表寬度
若是有錯誤的地方,歡迎同行指正!!