DevExpress SearchLookUpEdit使用回车选择首行数据

基本设置,绑定数据

                searchEdit.Properties.ValueMember = "ID";
                searchEdit.Properties.DisplayMember = "Name";
                searchEdit.Properties.DataSource = dt;
                searchEdit.Properties.Popup += Properties_Popup;

  

在popup事件中添加

 

        private void Properties_Popup(object sender, EventArgs e)
        {
            TextEdit txt = (sender as IPopupControl).PopupWindow.Controls.Cast<Control>().FirstOrDefault(item => item is SearchEditLookUpPopup).Controls.Cast<Control>().FirstOrDefault(item => item is LayoutControl).Controls.Cast<Control>().FirstOrDefault(item => item is TextEdit) as TextEdit;

            if (txt.Tag != null)
                return;

            txt.Tag = "KeyDown";
            txt.KeyDown += txt_KeyDown;
        }

        void txt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                TextEdit txt = sender as TextEdit;
                SearchLookUpEdit lookUpEdit = (txt.TopLevelControl as PopupSearchLookUpEditForm).OwnerEdit as SearchLookUpEdit;
                GridView gv = lookUpEdit.Properties.View as GridView;
                gv.FocusedRowHandle = 0;
                lookUpEdit.ClosePopup();
            }
        }

  

posted @ 2019-05-21 12:16  逍遥子k  阅读(941)  评论(0编辑  收藏  举报