views:

245

answers:

2

Is there any way that we can insert a new control in a panel on previous index as we can do with the List collection like this:

List.Insert(2,Value);

I am working with C# winforms.

I want to do this because I want to access the controls in a specific order, like this:

Control c = panelThumbnail.GetNextControl(control, true);

It gives the controls in order of their indexes. Is there any other way to solve the problem?

A: 

The order of controls returned by Control.GetNextControl is based on the TabIndex of the contained controls. To change the order of the returned controls, change the TabIndex of each control to match the order you want them returned.

alabamasucks
I also findout the way to change the index that after Add the child to the Panel then call SetChildIndex. But its right that ontrol.GetNextControl is based on the TabIndex. Thanks Alabamasucks for correction.
qulzam
Now the problem is that the tabindex is not a unique which disturb my logic. is it possible to make tabindex unique
qulzam
A: 

You can add the new controls to an array of controls. Then you can access the controls through the array in any order, instead of using .GetNextControl.

xpda