.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Double click in list box to fire OK button

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Ed.Jobe
750 Views, 2 Replies

Double click in list box to fire OK button

I have a list box with text items in it. When I click on the OK button on the form it returns the string selected. I want to utilize the listbox DoubleClick event to fire the OK button. I've called the handler method for the OK button, but it just runs the code and the form stays open. I need it to act as if the user clicked the OK button. This method worked in vba. Any ideas how to do it in a C# windows form?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: Ed.Jobe

The fact that your DoubleClick event handler calls the OK button's handler method and the form/dialog box does not close as if OK button is clicked indicates that the OK button has its property "Dialogresult" being set either OK, or Cancel, which means closing/hiding the form where the button is hosted.

 

If you want to let the listbox's DoubleClick and the OK button's Click event handler share the same handling method, you need to set the button's DialogResult prperty to None, and then iin the handling method to call Form.DialogResilt=OK/Cancel.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
Ed.Jobe
in reply to: norman.yuan

Thanks Norman, that was simple. I did a test and you don't need to set the button's DialogResult to None. It worked both ways. Seems like setting the property in the Click event just overrides what was previously set.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost