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 = "";//清空默认值

设置下拉列表宽度

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值