Control wont take focus

G

Guest

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
 
P

Peter Duniho

vbtrying said:
[...]
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
 
G

Guest

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 said:
vbtrying said:
[...]
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
 
P

Peter Duniho

vbtrying said:
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.

I'm not on a high horse. I'm trying to help you.

There's not a single person here who can answer your question as stated.

You haven't been specific enough about what's not happening that you
expect to happen, and since the Focus() method does in fact do exactly
what it's documented to do, if you are calling it and not achieving the
results you expect, that is either due to it not being used correctly,
or due to you having the wrong expectation for what it will do.

In either case, both the problem description as well as the context of
the code are important with respect to answering the question, and you
haven't provided enough of either.

This is not a bulletin board, it's a newsgroup and this newsgroup works
fine for most people. Some are not well-suited to receiving advice.
For those people, a newsgroup or bulletin board or web forum or any
other place where people ask questions and other people answer them is
unlikely to work well.

If you cannot extract yourself from your defensiveness, you are likely
to find yourself in that category of people for whom this newsgroup
isn't going to be useful.

Pete
 
G

Guest

Since this is a public "newsgroup", I can't tell you where you can stick your
comments.
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

vbtrying said:
Since this is a public "newsgroup", I can't tell you where you can stick
your
comments.

For a guy asking for help you have a very scre....ed actitud

If you did not understand Pete's answer just say it.
 
G

Guest

Can you spell? A T T I T U D E , not actitud.

I understood his answer. He had none. I'm not sure what he wanted because I
thought my question explained it all. So I'm sure it's my fault.
 
P

Peter Duniho

vbtrying said:
Can you spell? A T T I T U D E , not actitud.

Well, at least you understood what he wrote, even if you find it
necessary to criticize someone for some irrelevant error.
I understood his answer.

So you claim.
He had none.

That's not true. I provided lots of information, including the fact
that there's nothing fundamentally wrong with the Control.Focus() method.
I'm not sure what he wanted because I
thought my question explained it all.

Sounds to me as though you did not understand my answer after all, in
spite of your claim otherwise. Your question definitely did not
"explain it all". The point of my response was to try to explain that
to you.
So I'm sure it's my fault.

Whatever's your fault, you can easily rectify the situation by calming
down, apologizing, and starting over.

Absent that, I think it's likely you're not going to get much in the way
of help here, especially in this thread. Very few people bother to help
people who act the way you have done here. Not everyone looks closely
at the name of the person writing the question, so you might still get
responses to questions in new threads (assuming you can keep your cool
in those other threads). But those who do pay attention to the poster's
name are unlikely to bother in any other thread as well, based on your
behavior here.

Pete
 
G

Guest

Pete,

I'll try to explain one more time (I doubt it will be to your satisfaction):

I'm in a SWITCH piece of code: If the user does not enter HOURS worked for
that day, the switch statement notifies the user, then (i try) to set focus
back to the hours control. What happens, is that the FOCUS statement is
ignored, and control continues through the switch piece of code and fails
when it tries to convert the blank hours to a double variable
(Convert.ToDouble(txtHours.txt))

I guess my question is: How to break out of the switch statement when it
fails the condition?

If you don't reply, I'll understand.
 
P

Peter Duniho

vbtrying said:
[...]
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
 
G

Guest

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 said:
vbtrying said:
[...]
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
 
P

Peter Duniho

vbtrying said:
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
 
G

Guest

Childish behavior, um, let me see. Could it be that you have a "need" to get
the last word in?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top