Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Me.Controls help 1

Status
Not open for further replies.

artyk

Programmer
Apr 5, 2006
163
US
Hi, everyone. I am fairly new to VB.Net, meaning I have done a couple of pretty simple apps. The one I am currently working on is quite a bit more complex, however.

What I have is a scheduling program that I need to be able to add controls to a form on the fly. I have a general idea of how I want it to work, but I'm not sure of the commands I need. The part I am working on, the user selects a day of the week from a combobox and the form is populated based on the table data. It works great, but I need it to check how many lines (controls to display the data) are on the form and add/subtract lines as needed.

I have the controls named such as "dtpStaffTimeEnd1" and I'm trying to set it up so that it searches the form for the control with the highest number so that I can determine if I need to add or subtract groups of controls. I was thinking something along the lines of Me.Controls.Find, but I've never used that before and was unsure of the correct usage.

If someone could point me in the right direction, I would be appreciative. Or if there is a better way to do what I'm trying to do I would obviously be open to that also.

Thanks!
 
If you add the controls to a transparent panel, instead of the form itself, you can use something like MyPanel.Controls.Count to determine how many controls you currently have.

Here is one other suggestion:

* If you have an upper limit of controls, you might create them all and hide/unhide them as needed instead of creating/destroying everytime.

 
Thanks for the suggestions. There won't be an upper limit for this particular form. I had considered making one, but I would like to keep it as flexible as possible. There is also a Me.Controls.Count as well, but I was hoping I could isolate the number in the form name and use that and an array of the controls to find the highest number of the given control somehow.
 
Also remember the .Tag property of the controls, where you can store extra information--for example, an integer. You could loop through the controls for the highest .Tag easier than splitting the string to get the number.

You can also keep a variable with the number of controls you have created to keep track of the count.
 
That's (the .tag) an excellent idea! Thanks, that seals it, that's what I will use. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top