473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

can we change an index of an object?

Tee
Hi,

Does anyone know how to change an index of an object?

This is what I want to do.

eg: I have 5 controls in a panel.
index from 0 to 4, after I remove the 3rd control (index 2), I want to
change the control with index 3 to 2, and 4 to 3. (push up) ... so when I
add new control to the panel, the new control will have the index 4.

Is this possible? if not, can anyone suggest me a solution?

Thanks,
Tee
Jul 21 '05 #1
4 1663
Use Control.ControlCollection.SetChildIndex Method

"Tee" wrote:
Hi,

Does anyone know how to change an index of an object?

This is what I want to do.

eg: I have 5 controls in a panel.
index from 0 to 4, after I remove the 3rd control (index 2), I want to
change the control with index 3 to 2, and 4 to 3. (push up) ... so when I
add new control to the panel, the new control will have the index 4.

Is this possible? if not, can anyone suggest me a solution?

Thanks,
Tee

Jul 21 '05 #2
"Tee" <th*@streamyx.com> wrote:
eg: I have 5 controls in a panel. [...]
I want to change the control with index 3 to 2, and 4 to 3.
(push up) ... so when I add new control to the panel, the
new control will have the index 4.
Is this possible?


I don't think so. However, you can achieve this by removing the
controls from the panel, and then adding them back in a different
order. I had to do this with TabPages on a TabControl when the VS.NET
Forms Designer kept switching them around.

Why do you need to change the indexes?
If you're doing something like this:

for (int i = 0; i < myPanel.Controls.Count; i++)

.... you can rewrite it more clearly like this:

foreach (Control ctl in myPanel.Controls)

P.
Jul 21 '05 #3
Property Panel.Controls and TabControl.TabPages are different stories.
Panel.Controls return Control.ControlCollection which has SetChildIndex
Method.
TabControl.TabPages return TabControl.TabPageCollection.

"Paul E Collins" wrote:
"Tee" <th*@streamyx.com> wrote:
eg: I have 5 controls in a panel. [...]
I want to change the control with index 3 to 2, and 4 to 3.
(push up) ... so when I add new control to the panel, the
new control will have the index 4.
Is this possible?


I don't think so. However, you can achieve this by removing the
controls from the panel, and then adding them back in a different
order. I had to do this with TabPages on a TabControl when the VS.NET
Forms Designer kept switching them around.

Why do you need to change the indexes?
If you're doing something like this:

for (int i = 0; i < myPanel.Controls.Count; i++)

.... you can rewrite it more clearly like this:

foreach (Control ctl in myPanel.Controls)

P.

Jul 21 '05 #4
Tee
As I said, I want to make a index ID push up.
so let's say, I removed the control index 3, the 4 will take place the 3
position.
And when I want to remove the new index 3, I just call Controls.RemoveAt(3),
instead of I need to call RemoveAt(4), which makes it don't look right, as
the 4 is already in the index 3 position after 3 got removed.

"Paul E Collins" <fi******************@CL4.org> wrote in message
news:cm**********@hercules.btinternet.com...
"Tee" <th*@streamyx.com> wrote:
eg: I have 5 controls in a panel. [...]
I want to change the control with index 3 to 2, and 4 to 3.
(push up) ... so when I add new control to the panel, the
new control will have the index 4.
Is this possible?


I don't think so. However, you can achieve this by removing the
controls from the panel, and then adding them back in a different
order. I had to do this with TabPages on a TabControl when the VS.NET
Forms Designer kept switching them around.

Why do you need to change the indexes?
If you're doing something like this:

for (int i = 0; i < myPanel.Controls.Count; i++)

... you can rewrite it more clearly like this:

foreach (Control ctl in myPanel.Controls)

P.

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle...
0
by: Andy Eshtry | last post by:
I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox. EIN must be (for...
4
by: Tee | last post by:
Hi, Does anyone know how to change an index of an object? This is what I want to do. eg: I have 5 controls in a panel. index from 0 to 4, after I remove the 3rd control (index 2), I want to...
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
3
by: wg | last post by:
I have written a class to contain tags that are loaded from a spreadsheet. I can load the value ok. But from another class I would like to change a value inside the arraylist. Here is my code (see...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
5
by: Gary | last post by:
I am using List<MyClassto store a bunch of MyClasses. And in my program, I want to change the content of one class in this list. However, it seems to me that this list keeps an original copy and is...
1
by: thesti | last post by:
hi, i'm going to develop a program using VB .NET. i've bound some textboxes to the same DataSource (DataSet1.Tables(0). and i enable the user to type the primaryKey of the data in the Table,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.