GetNextControl() method in .NET - Janus Pienaar

Janus Pienaar

Made in South Africa

GetNextControl() method in .NET

O Boy, how something so simple can turn out to be...well...not so simple.

Am I having a blonde day or what the hell is going on here??  I've created a custom control with some Dropdown boxes and Textbox on it. Very basic.

When the user selects an item in the Dropdown...the text in the textbox next to the dropdown must be changed. In order the get to the Textbox I used GetNextControl() method.

My code was as follows: On the Combo's SelectionChanged event

private void comboProducts_SelectionChanged(object sender, EventArgs e)

{

SupplierProductArtifactControl control = (SupplierProductArtifactControl)sender;

Control controlNext = this.GetNextControl(control , true);

controlNext .Text = “Some Text“;

}

Well, in this case the GetNextControl() method did NOT select the next control.

The controlNext was still the combobox.

But changing the line :

Control controlNext = this.GetNextControl(control , true);

to

Control controlNext = this.GetNextControl(ActiveControl , true);

Made the difference and it worked.

Now what is the difference between “control” in first example and “ActiveControl” in second?

Posted: May 13 2005, 11:01 AM by janus | with 2 comment(s)
Filed under:

Comments

surbhi said:

it worked for me too!

i guess GetNextControl works differently when control is not basic windows.forms.control. in my case it was Infragistic control.

# September 12, 2008 11:06 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: