Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Control wont take focus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vbtrying - 27 Aug 2007 20:14 GMT
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
Peter Duniho - 27 Aug 2007 20:45 GMT
> [...]
> The following code does NOT work:
[quoted text clipped - 12 lines]
>
> 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
vbtrying - 27 Aug 2007 20:56 GMT
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.

> > [...]
> > The following code does NOT work:
[quoted text clipped - 28 lines]
>
> Pete
Peter Duniho - 27 Aug 2007 21:07 GMT
> 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
vbtrying - 27 Aug 2007 21:16 GMT
Since this is a public "newsgroup", I can't tell you where you can stick your
comments.

> > 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
[quoted text clipped - 27 lines]
>
> Pete
Ignacio Machin ( .NET/ C# MVP ) - 27 Aug 2007 22:07 GMT
hi,

> 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.
vbtrying - 27 Aug 2007 23:56 GMT
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.

> hi,
>
[quoted text clipped - 5 lines]
>
> If you did not understand Pete's answer just say it.
Peter Duniho - 28 Aug 2007 00:52 GMT
> 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
vbtrying - 28 Aug 2007 02:26 GMT
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.

> > Can you spell?    A T T I  T U D E  ,   not actitud.
>
[quoted text clipped - 33 lines]
>
> Pete
Peter Duniho - 28 Aug 2007 03:12 GMT
> [...]
> 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
vbtrying - 29 Aug 2007 02:42 GMT
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.

> > [...]
> > If you don't reply, I'll understand.
[quoted text clipped - 9 lines]
>
> Pete
Peter Duniho - 29 Aug 2007 04:52 GMT
> 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
vbtrying - 29 Aug 2007 13:24 GMT
Childish behavior, um, let me see. Could it be that you have a "need" to get
the last word in?

> > Don't wait too long for an apology from me.
>
[quoted text clipped - 24 lines]
>
> Pete
Peter Duniho - 29 Aug 2007 18:04 GMT
> Childish behavior, um, let me see. Could it be that you have a "need" to get
> the last word in?

Nope.  How about you?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.