Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to insert Controls at a specific location within the Controls collection when building a dynamic table.

Posted on 2011-02-21
5
Medium Priority
?
470 Views
Last Modified: 2012-05-11
Hi,

I am building a dynamic table which contains multiple rows and each cell contains 7 cells. One of the cells has 2 textboxes. I want to add a label to that cell at runtime. Currently I am only using "add" so it is the last control in. How can I insert the label before the first TextBox?

At present I am doing

cells(6).controls.add(myLabel)

If I want to add it before Textbox2 I do the following

cells(6).controls.Remove(Textbox1)
cells(6).controls.Remove(Textbox2)
cells(6).controls.add(myLabel)
cells(6).controls.Remove(Textbox1)
cells(6).controls.add(TextBox2)

Is there not a better way of inserting a control at a specific location in the collection without removing controls?

Thanks,

Sam
0
Comment
Question by:SamJolly
[X]
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
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34942085
There should be an "AddAt" method on the collection that lets you specify the index to insert at:
cells(6).Controls.AddAt(0, myLabel)

Open in new window

0
 

Author Comment

by:SamJolly
ID: 34942184
carl,

thanks for this. So assuming I need to use 2 positions depending on Unit (£ or %) then the following would be correct?

If I had 2 textboxes2

TextBox1
Textbox2

then for "£" I would need :

 cells(6).Controls.AddAt(0, myLabel)

and for "%" I would need:

 cells(6).Controls.AddAt(2, myLabel)

Is my thinking and code correct?

Thanks,

Sam

0
 

Author Comment

by:SamJolly
ID: 34942196
Actually for the "%" I can just do an "Add".

Sam
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34942204
Yes, you only really need to use AddAt() if you want to force a specific location. Add() will add to the end anyway.
0
 

Author Closing Comment

by:SamJolly
ID: 34942484
thanks, very helpful
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

636 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