[DevExpress]为LookUpEdit添加删除按钮

关键代码:

        public static void AddDeleteButton(this LookUpEdit lue, string prompttext)

        {

            prompttext = string.IsNullOrEmpty(prompttext) ? "删除选中项" : prompttext;

            lue.Properties.Buttons.AddRange(new EditorButton[] 

            {   

                new EditorButton(

                    ButtonPredefines.Delete,

                    "删除", -1, true, true, false, ImageLocation.MiddleCenter, 

                    null, 

                    new KeyShortcut(Keys.Delete),

                    new SerializableAppearanceObject(),

                    prompttext, 

                    "Delete",

                    null,

                    true) 

            });

            lue.ButtonClick += new ButtonPressedEventHandler(lue_ButtonClick);

        }

        static void lue_ButtonClick(object sender, ButtonPressedEventArgs e)

        {

            if (e.Button.Kind == ButtonPredefines.Delete)

            {

                LookUpEdit _curLue = sender as LookUpEdit;

                _curLue.EditValue = null;

            }

        }

使用示例:

            this.lookUpEdit1.BindWithAutoCompletion(PersonList, "Name", "Name", "输入需要搜索的....");

            this.lookUpEdit1.AddDeleteButton("删除选中数据....");

使用效果:

image

希望有所帮助!微笑

你可能感兴趣的:(DevExpress)