DevExpress control library ---- LookUpEdit control and GridLookUpEdit control, gridlookupedit usage
DevExpress control library ---- use of the LookUpEdit control and GridLookUpEdit Control
I. Simple USE OF THE LookUpEdit control: The following is the basic data used.
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 Data Collector", "MS scanner", "105SL", "TSC", "PH880 ", "MS320 portable printer", "PA700", "DSX800 computer", "HP printer"}; 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 ;}}
First look at the effect:
Data Binding:
List<Product> list = Entility.GetProductList();lookUpEdit1.Properties.DataSource = list;
Add the displayed column: locate the attribute list-Add the column to be bound. If no column is added, columns are automatically generated based on the attribute name.
Simple property settings:
// Double-click the lookUpEdit1.Properties drop-down list. showDropDown = ShowDropDown. doubleClick; lookUpEdit1.Properties. immediatePopup = true; // The lookUpEdit1.Properties drop-down list is displayed. textEditStyle = TextEditStyles. standard; // allow the input of lookUpEdit1.Properties. dropDownRows = 12; // The default row lookUpEdit1.Properties. popupWidth = 350; // set the broadband lookUpEdit1.Properties. nullText = ""; // clear the default value
Ii. Simple use of the GridLookUpEdit Control
Effect:
Data Binding:
List<Product> list = Entility.GetProductList(); gridLookUpEdit1.Properties.DataSource = list;
Add the displayed data column: bind the data to set the column width.
GridLoolUpEdit performs fuzzy filtering based on the fields bound to DisplayMember by default.
Set the filtering function based on multiple columns:
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); })); }
Display row numbers for filtered Columns
private void gridLookUpEdit1View_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } }
Some simple property settings:
// Double-click the gridLookUpEdit1.Properties drop-down list. showDropDown = ShowDropDown. doubleClick; gridLookUpEdit1.Properties. immediatePopup = true; // display the drop-down list gridLookUpEdit1.Properties. textEditStyle = TextEditStyles. standard; // you can enter gridLookUpEdit1.Properties. nullText = ""; // clear the default value
Set the width of the drop-down list
If something is wrong, please let us know !!