GetNextControl - How to use???

Posted on 2003-03-06
Medium Priority
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:

   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.


PS: sorry for the low points, but that's all I have left!
Question by:NetMeister
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

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!


Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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