Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

GetNextControl - How to use???

Posted on 2003-03-06
2
Medium Priority
?
3,636 Views
Last Modified: 2012-08-13
When I Enter a particular control on a WinForm, I need to know the previous control. I have the following code:

private void txtFirstNames_Enter(object sender, System.EventArgs e)
{
    Control currCtl = (Control)sender;  //current control
    Control prevCtl = currCtl.GetNextControl(currCtl, false)   //previous control
    ...
}

The problem with the above code is that prevCtl = null after executing the line.

According to the Microsoft docs (which are totally inadequate - with NO code examples), the format of the GetNextControl method is:

GetNextControl(
   Control ctl, //control to start searching from
   boolean direction  //false - go back; true - go forward
)

What am I doing wrong???? A code snippet will help as well as an explanation of why my code is not working. I'm sure it's something simple.

TIA - NM.

PS: sorry for the low points, but that's all I have left!
0
Comment
Question by:NetMeister
2 Comments
 
LVL 4

Accepted Solution

by:
MrGhost earned 80 total points
ID: 8086381
You can't call GetnextControl on the Control which doesn't have childs controls, you shoud try to change:
Control prevCtl = currCtl.GetNextControl(currCtl, false)   //previous control

in somthing like this Control prevCtl = ActiveForm.GetNextControl(currCtl, false)  

because both controls are child controls of a form!

0
 

Expert Comment

by:stevie_bm
ID: 8102213
An alternative (if you're not using controls as direct children of the form) is to use:
Control prevCtl = currCtl.Parent.GetNextControl(currCtl, false)   //previous control
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question