473,287 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Not losing focus on current textbox when pressing a different button

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
Sep 12 '06 #1
3 5373
"Patrick [MSFT]" <pr**@online.microsft.comwrote in message
news:eh**************@TK2MSFTNGP03.phx.gbl...
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).
This is not a good way to do validation. I have only ever encountered 1 app
that does it this way and I uninstalled it pretty quick. This is annoying
for the user because they might want to fill in other fields first or tab to
a close button. Getting rid of this behaviour will solve your problem.
Instead check for a valid customer id when they push the ok button. If they
need to fill in this id to get all the other fields available then just
disable every other field on the form.

Michael
Sep 12 '06 #2
I guess that would depend on what your app is doing. In my case, as I
mentioned the accounting application does it this way. The object of the
new .NET app is to mimic Great Plains and so that it would appear seemless
to that application.

As for why you might code an application this way, what if I validate after
the whole transaction is complete:

1. you call me up and want to place an order for a bunch of items.
2. I enter in what I _think_ is your customer id.
3. I then enter in a bunch of items one at a time
4. But perhaps I enter in the customer id wrong. You have a contract with
me to provide customer/item specific pricing but since I typed in the
customer wrong when I entered it. Since I have the wrong ID, when I'm
quoting you the price over the phone it'll be wrong.
5. Also I might have mis-typed my items wrong on entry and so when I told
you I had 5 "widgets" on hand as it turns out I really didn't because it
wasn't entered correctly and reserved by inventory. So by the time I enter
your order and press "submit" some other user just entered 1 item and
allocated by widget already. That really needs to be realtime.

Your other idea is a good one, disable everything else that relies on this
one field being valided first. I think I'll probably implement something
like this.

As it turns out, the solution was apparently obvious. I just missed it
about a dozen times as I didn't realize as the property really applies to
_other_ fields. I switched the "CausesValidation" property on my button to
False. So now when I press my button the validate event doesn't run and I
open my window and set focus back onto the text field again. Not quite as
convenient as Dexterity but darn close and good enough for me.

thanks for your response,
patrick
microsoft dynamics
This is not a good way to do validation. I have only ever encountered 1
app
that does it this way and I uninstalled it pretty quick. This is annoying
for the user because they might want to fill in other fields first or tab
to
a close button. Getting rid of this behaviour will solve your problem.
Instead check for a valid customer id when they push the ok button. If
they
need to fill in this id to get all the other fields available then just
disable every other field on the form.

Michael

"Michael C" <no****@nospam.comwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
"Patrick [MSFT]" <pr**@online.microsft.comwrote in message
news:eh**************@TK2MSFTNGP03.phx.gbl...
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).

This is not a good way to do validation. I have only ever encountered 1
app
that does it this way and I uninstalled it pretty quick. This is annoying
for the user because they might want to fill in other fields first or tab
to
a close button. Getting rid of this behaviour will solve your problem.
Instead check for a valid customer id when they push the ok button. If
they
need to fill in this id to get all the other fields available then just
disable every other field on the form.

Michael


Sep 12 '06 #3
"Patrick [MSFT]" <pr**@online.microsft.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>I guess that would depend on what your app is doing. In my case, as I
mentioned the accounting application does it this way. The object of the
new .NET app is to mimic Great Plains and so that it would appear seemless
to that application.
I really don't think it's necessary to mimic the UI faults of great plains
though. :-)
As for why you might code an application this way, what if I validate
after
the whole transaction is complete:
Ok, that's fair enough and might not suit this particular case. But the
point is you want to find *something* besides forcing the focus to remain in
the textbox. This is possibly the worst UI sin you can comit :-) If
everything else is grayed out there is no need to force focus to remain in
the textbox.

Michael
Sep 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
1
by: VMI | last post by:
In my Windows app, if I'm in a multi-line textbox and I'm writing a postal address (ie. write ist line and press <Enter>, write 2nd line and press <Enter>, etc...) how can I make sure that the...
1
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the...
3
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would...
10
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total...
2
by: Amit D.Shinde | last post by:
I am having 4 controls on my form name and tab index property of them is as follows Name Tabindex Textbox1 0 Radiobutton1 1 Radiobutton2 ...
5
by: Tosch | last post by:
I have a usercontrol with a label, a textbox, a treeview, a grid and a couple of checkboxes. The usercontrol is hosted on a form together with a cancel and a accept button. This form is used to...
0
by: Stefan De Schepper | last post by:
Dear NG, I created a gridlike usercontrol. When clicking on a cell a textbox (or other control, depending on the cell's editortype) is shown. When some other control gets the focus, the textbox...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.