473,387 Members | 1,520 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,387 software developers and data experts.

Control wont take focus

I am using a switch statement, to check for valid user hours. If the hours
control is blank, I want to place the cursor back to the hours control for
the user.

The following code does NOT work:

switch (txtHours.Text)
{
case "":
MessageBox.Show("No hours entered.\nYou must enter hours
for this record.", "Bad Value for Hours", MessageBoxButtons.OK,
MessageBoxIcon.Error);
txtHours.Focus();
break;
default:
break;
}

Has anybody tried to do this before? Am I using it incorrectly?

Thanks,
Terry
Aug 27 '07 #1
7 1804
vbtrying wrote:
[...]
The following code does NOT work:

switch (txtHours.Text)
{
case "":
MessageBox.Show("No hours entered.\nYou must enter hours
for this record.", "Bad Value for Hours", MessageBoxButtons.OK,
MessageBoxIcon.Error);
txtHours.Focus();
break;
default:
break;
}

Has anybody tried to do this before? Am I using it incorrectly?
How does it "NOT work"? Where do you execute the code?

The Focus() method does generally work, and I have in fact used it when
doing textbox value validation. So the general technique is sound.

But if you aren't putting the code somewhere that guarantees that the
focus will be left alone after you call Focus(), you could easily wind
up not seeing any focus change.

You need to be more specific if you want an answer though. You should
post a concise-but-complete example of code that reliably reproduces the
problem (and of course, you should be more precise in describing the
problem than "does not work").

Pete
Aug 27 '07 #2
Pete, get off your high horse guy! "You need to be more specific if you want
an answer". Don't answer if you think the question doesn't suite your needs
as fas as clarity.

You are the reason bulletin boards don't work.


"Peter Duniho" wrote:
vbtrying wrote:
[...]
The following code does NOT work:

switch (txtHours.Text)
{
case "":
MessageBox.Show("No hours entered.\nYou must enter hours
for this record.", "Bad Value for Hours", MessageBoxButtons.OK,
MessageBoxIcon.Error);
txtHours.Focus();
break;
default:
break;
}

Has anybody tried to do this before? Am I using it incorrectly?

How does it "NOT work"? Where do you execute the code?

The Focus() method does generally work, and I have in fact used it when
doing textbox value validation. So the general technique is sound.

But if you aren't putting the code somewhere that guarantees that the
focus will be left alone after you call Focus(), you could easily wind
up not seeing any focus change.

You need to be more specific if you want an answer though. You should
post a concise-but-complete example of code that reliably reproduces the
problem (and of course, you should be more precise in describing the
problem than "does not work").

Pete
Aug 27 '07 #3
vbtrying wrote:
[...]
If you don't reply, I'll understand.
I'm not so sure of that. I suspect that you will think a lack of a
response on my part is due to an inability to answer the question, when
in fact it would be due to the lack of an apology from you for your
behavior.

If my suspicion is correct, then you don't understand.

I guess we'll see.

Pete
Aug 28 '07 #4
Don't wait too long for an apology from me. If you can't answer the question,
or just don't want to, fine. But don't hide behind the premise that you're
waiting for an apology first before you answer questions.

You must enjoy the world you live in.

"Peter Duniho" wrote:
vbtrying wrote:
[...]
If you don't reply, I'll understand.

I'm not so sure of that. I suspect that you will think a lack of a
response on my part is due to an inability to answer the question, when
in fact it would be due to the lack of an apology from you for your
behavior.

If my suspicion is correct, then you don't understand.

I guess we'll see.

Pete
Aug 29 '07 #5
vbtrying wrote:
Don't wait too long for an apology from me.
Why would I wait at all? Rest assured, I'm not sitting around waiting
for you to do anything at all.
If you can't answer the question,
or just don't want to, fine.
As if you could direct me otherwise?
But don't hide behind the premise that you're
waiting for an apology first before you answer questions.
Hide? Um, whatever.
You must enjoy the world you live in.
I do, actually. I live in a world where I have no reason to put up with
jerks who fly off the handle at the least possible provocation, taking
insult where none was intended, and who cannot be bothered to apologize
for their atrociously childish behavior.

Your question is not really that hard. You should think carefully about
why it is no one else has jumped in to help you out. It's not like
people are falling over themselves to answer your question. And the
lack of replies is not because it's too hard for everyone else.

Pete
Aug 29 '07 #6
Childish behavior, um, let me see. Could it be that you have a "need" to get
the last word in?

"Peter Duniho" wrote:
vbtrying wrote:
Don't wait too long for an apology from me.

Why would I wait at all? Rest assured, I'm not sitting around waiting
for you to do anything at all.
If you can't answer the question,
or just don't want to, fine.

As if you could direct me otherwise?
But don't hide behind the premise that you're
waiting for an apology first before you answer questions.

Hide? Um, whatever.
You must enjoy the world you live in.

I do, actually. I live in a world where I have no reason to put up with
jerks who fly off the handle at the least possible provocation, taking
insult where none was intended, and who cannot be bothered to apologize
for their atrociously childish behavior.

Your question is not really that hard. You should think carefully about
why it is no one else has jumped in to help you out. It's not like
people are falling over themselves to answer your question. And the
lack of replies is not because it's too hard for everyone else.

Pete
Aug 29 '07 #7
vbtrying wrote:
Childish behavior, um, let me see. Could it be that you have a "need" to get
the last word in?
Nope. How about you?
Aug 29 '07 #8

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

Similar topics

4
by: Colleyville Alan | last post by:
I have 2 command buttons on a form. I want the first one to be enabled and the second one to be disabled when the form is opened. That works fine. Then, after the user has pressed the first...
2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
2
by: bill | last post by:
I have the following user control in my project simply for setting focus to a control: Public Class SetFocus Inherits System.Web.UI.UserControl
2
by: Tom | last post by:
I am developing a VB.NET user control that is composed of a component control (along with some classes, etc). This is probably a stupid question, and should be easy, but I must be having a brain...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
9
by: Zytan | last post by:
http://msdn2.microsoft.com/en-us/system.windows.forms.control.focus(VS.80).aspx this page says: "Focus is a low-level method intended primarily for custom control authors. Instead, application...
3
by: Nathan Laff | last post by:
I have a custom Control that is a label, however I inherit from Control... 1) I override onClick and do a DrawFocusRectangle, that works great. How do I clear the focus rectangle once something...
5
by: colin | last post by:
Hi, Ive got a 3d model editor wich im developing with XNA c# development environment, using the game window to display the wireframe mesh in 3d. however I need to use some other windows too,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.