Let me preface this with the goal I'm trying to achieve is mimic a feature
of another language (Dexterity used by Microsoft Dynamics) and so while a
filling a drop down list is a workable solution I'd rather do it like
Microsoft Dynamics does and use separate textbox and lookup button.
What I have is, simply, is a C# winform, a textbox and a pushbutton.
On the textbox, on the validating event of the textbox I check my customer
table using ADO and verify that the Customer ID entered is indeed in the
database. If it is not, give a message and keep focus on the textbox. If
it is in the database, then everything is OK (of course).
The pushbotton is a "lookup". In it, I open a new form which fills a grid
with all the customers in the system and allows the user to search/find.
When they have selected the customer, the Select button on the lookup is
pressed and the CustomerID is returned to textbox.
The problem:
In Dexterity I can basically set a property on my pushbutton that
essentially allows me to press the button but not lose focus on my textbox.
Ideally what happens is that I would perhaps enter in "BI" into the textbox,
press the lookup pushbutton, and the form opening then starts with all the
items in the list beginning with "BI" to give me a bit of a headstart in my
lookup to find the correct customer id.
What happens for me, currently, is that I can enter in "BI" into my textbox
and press my pushbutton lookup. But of course the validating event runs,
checks for a customer "BI" which doesn't exist, and then gives my error
message.
I was thinking of trying perhaps a MouseDown event on the pushbutton but the
Leaving event of the textbox fires before that event.
My solutions I thought of so far include:
In the textbox Validating event, check to see where the mouse is and compare
to the coordinates of the pushbutton. If over the pushbutton then don't
check the database and assumed the user pressed the lookup pushbutton.
Override the On_Paint event of my textbox. Draw a "button" onto the end of
the field itself. On the click event of the field (and mouse over to swith
the cursor from I-beam to arrow) check to see if I'm over the "button" I've
drawn on and if so then open my lookup form.
Instead of using an actual pushbutton, draw my own "button" on the form
itself. Use the click event of the form, check the coordinates, and if over
the "button" then open my form.
I'm not terribly well versed in Visual Studio 2005 as I've really only been
using it somewhat seriously for about 4 months now and I can't help but
think there has to be an easier way to do this. Or perhaps I'm just spoiled
by this kind of functionality in Dexterity?
thanks for any ideas you might come up with,
Patrick Roth
Microsoft Dynamics (formerly Microsoft Business Solutions)
Developer Support