So there’s a real pain when it comes to handling the KeyPress event of a RepositoryItemGridLookUpEdit control when you set the ImmediatePopup to “True”. Looking all over the DevExpress support center gave some clues but not a solid answer. I finally got it working and thought I’d share the solution just in case anyone else is having the same problem.
C# Example
private void repglkCities_Popup(object sender, EventArgs e) { DevExpress.Utils.Win.IPopupControl oSender; oSender = (DevExpress.Utils.Win.IPopupControl)sender; oSender.PopupWindow.KeyDown += new KeyEventHandler(PopupWindow_KeyDown); } private void PopupWindow_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm oSender = (DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm)sender; if (oSender.ResultValue != null) { //Do something here with the value } } } private void repglkCities_CloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e) { DevExpress.Utils.Win.IPopupControl oSenderl; oSender = (DevExpress.Utils.Win.IPopupControl)sender; oSender.PopupWindow.KeyDown -= new KeyEventHandler(PopupWindow_KeyDown); }
VB.NET Example
Private Sub repglkCities_Popup(sender As Object, e As EventArgs) Handles repglkInstrument.Popup Dim oSender As DevExpress.Utils.Win.IPopupControl oSender = DirectCast(sender, DevExpress.Utils.Win.IPopupControl) AddHandler oSender.PopupWindow.KeyDown, AddressOf PopupWindow_KeyDown End Sub Private Sub PopupWindow_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) If e.KeyCode = Keys.Enter Then Dim oSender As DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm = DirectCast(sender, DevExpress.XtraEditors.Popup.PopupGridLookUpEditForm) If oSender.ResultValue IsNot Nothing Then 'Do something with the value End If End If End Sub Private Sub repglkCities_CloseUp(sender As Object, e As DevExpress.XtraEditors.Controls.CloseUpEventArgs) Handles repglkInstrument.CloseUp Dim oSender As DevExpress.Utils.Win.IPopupControl oSender = DirectCast(sender, DevExpress.Utils.Win.IPopupControl) RemoveHandler oSender.PopupWindow.KeyDown, AddressOf PopupWindow_KeyDown End Sub
I hope this helps.
Your positions normally have a lot of really up to date info. Where do you come up with this? Just stating you are very innovative. Thanks again
An extremely interesting read, I may possibly not agree completely, but you do make some very valid points.
Thanks! Still is the way to do it in 2020. Seems quite awkward to me. Why you have to attach the handler each time the pop up comes up and then remove it? I tried other ways but none of them seemed to work.
Thanks again!