Form-ally Tired of This

Oct 10, 2012 22:36

I've spent a lot of time fighting through the idiosyncrasies of Windows Forms in the last month or so. Today's entertainment was the Browse Edit user control that I wrote and getting the validation to work the way that I wanted it to.

If the user clicks the browse button associated with the edit control, I want to allow the form that contains the control to pop an arbitrary dialog to collect the information. That turns out to be not too difficult once you get the EventHandler information set up correctly.

The problem was that I wanted to populate the edit control and validate it immediately if you hit the OK button in that arbitrary dialog, but not if you hit the Cancel button. Populating the edit control was easy. Triggering validation wasn't.

Until I finally figured out that my event handler function for the browse button in the Browse Edit control class could then call the function also in the Browse Edit control class that looks for a validation handler supplied by the parent form, because that will actually do what I wanted. If I check to make sure that I've stuffed text in the edit control, that is.

*thud* *thud* *thud*

Well, that only took a couple of hours to sort out...

work, computer, microsoft, musings, tech

Previous post Next post
Up