473,395 Members | 1,581 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,395 software developers and data experts.

Removing a Control Array

Hi,

i have been playing with some code that creates Control array labels that display dates down in a column in a Windows Form, but i am having trouble with removing Control array labels if a date range changes.

How do i remove a Control Array Label? in the case where the quantity of labels required where to be reduced by the Control Form control selecting the start and end dates.

some of the code that i have been playing with is attached below.



************************************
************************************

' remove the day array. 'this part doesnt work in my case..

For pd As Integer = 0 To 12
Me.Controls.Remove(lblDayArray(pd))

Next


strDayRow = datAStartDate.ToString("dddd,dd MMMM")

'using the label DayArray create days in rows
For i As Integer = 0 To DayDiff
lblDayArray(i) = New Label
Me.Controls.Add(lblDayArray(i))
With lblDayArray(i)
.TextAlign = ContentAlignment.MiddleRight
.BorderStyle = BorderStyle.None
.Location = New Point(intDInitLocationX, intLocationY)
.Size = New Size(intDInitSizeL, intInitSizeH)
.Text = strDayRow
.Name = "lblDay(i)"
End With

intLocationY = intLocationY + intSpacingY 'increments to next day
datAStartDate = dpStartDateRange.Value
datAStartDate.AddDays(1)
Next
Apr 16 '07 #1
4 8901
SammyB
807 Expert 512MB
You use the control's name as a parameter to the Remove.
Here's code that worked for me:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim newLabel(1 To 2) As Label
  3. Private Sub Command1_Click()
  4.     Set newLabel(1) = Me.Controls.Add("vb.label", "Label1", Me)
  5.     newLabel(1).Visible = True
  6.     newLabel(1).Move 0, 0, 500, 200
  7.     newLabel(1).Caption = "WOW!"
  8.  
  9.     Set newLabel(2) = Me.Controls.Add("vb.label", "Label2", Me)
  10.     newLabel(2).Visible = True
  11.     newLabel(2).Move 0, 300, 500, 200
  12.     newLabel(2).Caption = "Cool!"
  13. End Sub
  14. Private Sub Command2_Click()
  15.     Me.Controls.Remove newLabel(1).Name
  16. End Sub
  17. Private Sub Command3_Click()
  18.     Me.Controls.Remove newLabel(2).Name
  19. End Sub
Apr 18 '07 #2
Killer42
8,435 Expert 8TB
So the Remove method accepts a string (name) rather than a reference to the control, is that right? (I'm not .Net-savvy, yet.)
Apr 19 '07 #3
SammyB
807 Expert 512MB
So the Remove method accepts a string (name) rather than a reference to the control, is that right? (I'm not .Net-savvy, yet.)
I assumed from Dude's code that it was VB6 or VBA, so my post was written in VB6. In VB6 (and VBA), you use the name string, but in VB.NET you use the control object. (For VB.NET, see http://msdn2.microsoft.com/en-us/lib...on.remove.aspx)
Apr 19 '07 #4
Killer42
8,435 Expert 8TB
I assumed from Dude's code that it was VB6 or VBA, so my post was written in VB6. In VB6 (and VBA), you use the name string, but in VB.NET you use the control object. (For VB.NET, see http://msdn2.microsoft.com/en-us/lib...on.remove.aspx)
Oh! The Remove exists in VB6? I've never come across it. I thought it was somehow part of the technique used to simulate control arrays in VB.Net.

In Vb6, I would have just advised to Unload the elements of the array. In other words, Unload Newlabel1(1). It's just like loading or unloading a form.
Apr 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: D. Alvarado | last post by:
Hello, I have an array that contains numbers. Each element in the array is guaranteed to be unique. Let's say I have another variable which I know for certain is in the array, but I don't know...
1
by: Jeff Evans | last post by:
Hi, I was wondering if it's possible to remove a Control c from a Controls collection in the parent's event handler for an event fired by c. For instance let's say we have public class...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
7
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
9
by: Rob Meade | last post by:
Hi all, I have an array of lets say 10 items, I now want to remove an item, lets say from somewhere in the middle, based on one of the element values equalling a value I specify - is there a...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.