By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Removing a Control Array

P: 9
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
Share this Question
Share on Google+
4 Replies


SammyB
Expert 100+
P: 807
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

Expert 5K+
P: 8,434
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
Expert 100+
P: 807
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

Expert 5K+
P: 8,434
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

Post your reply

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