private void showPopup(bool showAll) { Form form = this.FindForm(); if (form == null) return; buildFilterExp(showAll, false); IList<BaseEntity> items = null; if (GetDataSource != null) { items = GetDataSource(this.Text); } else { Filter.PageNo = 0; Filter.PageSize = 0; items = DMT.Provider.Db.ReadList(EntityType, Filter).Cast<BaseEntity>().ToList(); if (items == null || items.Count == 0) { buildFilterExp(showAll, true); Filter.PageSize = 0; Filter.PageNo = 0; items = DMT.Provider.Db.ReadList(EntityType, Filter).Cast<BaseEntity>().ToList(); } } if (items.Count == 0) { if (lbc != null) { form.Controls.Remove(lbc); lbc = null; } return; } form.SuspendLayout(); if (lbc == null) { lbc = new ListBoxControl(); form.Controls.Add(lbc); lbc.KeyUp += (sender, e) => { if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter) { if (e.KeyCode == Keys.Enter) SelectedItem = lbc.SelectedItem; form.Controls.Remove(lbc); lbc = null; this.Focus(); } }; lbc.DoubleClick += delegate { SelectedItem = lbc.SelectedItem; form.Controls.Remove(lbc); lbc = null; this.Focus(); }; lbc.LostFocus += delegate { if (lbc.SelectedItem != null) SelectedItem = lbc.SelectedItem; else this.Text = ""; form.Controls.Remove(lbc); lbc = null; }; lbc.DrawItem += lbc_DrawItem; lbc.BringToFront(); } lbc.Width = this.Width; lbc.Location = form.PointToClient(this.PointToScreen(new Point(0, this.Height))); if (lbc.Location.Y + lbc.Height > form.Height) lbc.Location = new Point(lbc.Location.X, lbc.Location.Y - (lbc.Height + this.Height)); lbc.DataSource = items; lbc.SelectedIndex = -1; form.ResumeLayout(); }