jellydeal
asked on
VB : 'System.Windows.Forms.Panel' cannot be indexed because it has no default property
Hi,
When Im trying to add something to a runtime created panel I get this error :
'System.Windows.Forms.Pane l' cannot be indexed because it has no default property
This only happens if I try to add something outside of the ROUTINE it was created.
I declare the panel in a routine : Dim days_panel As New List(Of Panel)
Im assuming because its declared in a routine other routines cant see it?
But if I Declare it in the global variables I get the same error occurs for any reference of the panel..
Do I need to declare the default property? Cant seem to find out how!
Thanks for your time.
Barry
When Im trying to add something to a runtime created panel I get this error :
'System.Windows.Forms.Pane
This only happens if I try to add something outside of the ROUTINE it was created.
I declare the panel in a routine : Dim days_panel As New List(Of Panel)
Im assuming because its declared in a routine other routines cant see it?
But if I Declare it in the global variables I get the same error occurs for any reference of the panel..
Do I need to declare the default property? Cant seem to find out how!
Thanks for your time.
Barry
Mmm... can you post your complete code, please? At least the code in where you declare the panel, and the code in where you try to add anything to that panel.
ASKER
PANEL CREATION:
Private Sub Create_panel()
Dim month_panel As New List(Of Panel)
Do Until month_count > 12
'BUILD MONTH PANEL
month_panel.Add(New Panel)
With month_panel(month_count - 1)
.BorderStyle = BorderStyle.FixedSingle
.BackColor = Color.Yellow
.Width = 600
.Height = 50
.Location = New Point(10, (month_count * 49))
End With
Me.Controls.Add(month_pane l(month_co unt - 1))
monthx = Month(DateAdd("m", month_count - 1, start_date))
yearx = Year(DateAdd("m", month_count - 1, start_date))
pass_date = "01/" & monthx & "/" & yearx
offset = Get_offset_from_date(pass_ date) ' This is the offset to display the information on the grid -from the left
display_dates()
display_pattern()
display_roster()
month_count = month_count + 1
Loop
end sub
SUB ROUTINE THAT CAUSES ERROR
'Private Sub display_dates()
'Month_title.Text = UCase(MonthName(monthx, True))
'blank_offsets()
'Remaining Divs with the DATE, should be aligned with the correct Day, thanks to OFFSET DIVS
'cnt = 1
'Do Until cnt = grid_length - offset
' output = cnt
' work_date = DateAdd("d", cnt - 1, pass_date)
' If Month(work_date) <> monthx Then output = " "
' check_weekend(cnt + offset)
'=output PANEL FOR DATES
'cnt = cnt + 1
'Loop
Dim day_count As Integer
day_count = 1
Do Until cnt = grid_length
If cnt > offset And Month(work_date) = monthx Then
day_count = day_count + 1
work_date = DateAdd("d", cnt - 1, pass_date)
check_weekend(cnt + offset)
output = day_count.ToString
Else
output = ""
End If
'DISPLAY THE CELL
panel_day(cnt) = New Panel
lab_day(cnt) = New Label
panel_day(cnt).BorderStyle = BorderStyle.FixedSingle
panel_day(cnt).BackColor = Color.Pink
panel_day(cnt).Width = 23
panel_day(cnt).Height = 23
panel_day(cnt).Location = New Point((cnt - 1) * 22, 0)
month_panel(month_count).C ontrols.Ad d(panel_da y(cnt)) 'ERROR LINE
'ERROR :'System.Windows.Forms.Pan el' cannot be indexed because it has no default property
lab_day(cnt).Location = New Point(-1, -2)
lab_day(cnt).MinimumSize = New Size(24, 24)
lab_day(cnt).Size = New Size(24, 24)
lab_day(cnt).TextAlign = ContentAlignment.MiddleCen ter
If weekend(cnt) = 0 Then
lab_day(cnt).BackColor = Color.White
Else
lab_day(cnt).BackColor = Color.LightGreen
End If
lab_day(cnt).Text = output
panel_day(cnt).Controls.Ad d(lab_day( cnt))
'/ CELL
cnt = cnt + 1
Loop
End Sub
Private Sub Create_panel()
Dim month_panel As New List(Of Panel)
Do Until month_count > 12
'BUILD MONTH PANEL
month_panel.Add(New Panel)
With month_panel(month_count - 1)
.BorderStyle = BorderStyle.FixedSingle
.BackColor = Color.Yellow
.Width = 600
.Height = 50
.Location = New Point(10, (month_count * 49))
End With
Me.Controls.Add(month_pane
monthx = Month(DateAdd("m", month_count - 1, start_date))
yearx = Year(DateAdd("m", month_count - 1, start_date))
pass_date = "01/" & monthx & "/" & yearx
offset = Get_offset_from_date(pass_
display_dates()
display_pattern()
display_roster()
month_count = month_count + 1
Loop
end sub
SUB ROUTINE THAT CAUSES ERROR
'Private Sub display_dates()
'Month_title.Text = UCase(MonthName(monthx, True))
'blank_offsets()
'Remaining Divs with the DATE, should be aligned with the correct Day, thanks to OFFSET DIVS
'cnt = 1
'Do Until cnt = grid_length - offset
' output = cnt
' work_date = DateAdd("d", cnt - 1, pass_date)
' If Month(work_date) <> monthx Then output = " "
' check_weekend(cnt + offset)
'=output PANEL FOR DATES
'cnt = cnt + 1
'Loop
Dim day_count As Integer
day_count = 1
Do Until cnt = grid_length
If cnt > offset And Month(work_date) = monthx Then
day_count = day_count + 1
work_date = DateAdd("d", cnt - 1, pass_date)
check_weekend(cnt + offset)
output = day_count.ToString
Else
output = ""
End If
'DISPLAY THE CELL
panel_day(cnt) = New Panel
lab_day(cnt) = New Label
panel_day(cnt).BorderStyle
panel_day(cnt).BackColor = Color.Pink
panel_day(cnt).Width = 23
panel_day(cnt).Height = 23
panel_day(cnt).Location = New Point((cnt - 1) * 22, 0)
month_panel(month_count).C
'ERROR :'System.Windows.Forms.Pan
lab_day(cnt).Location = New Point(-1, -2)
lab_day(cnt).MinimumSize = New Size(24, 24)
lab_day(cnt).Size = New Size(24, 24)
lab_day(cnt).TextAlign = ContentAlignment.MiddleCen
If weekend(cnt) = 0 Then
lab_day(cnt).BackColor = Color.White
Else
lab_day(cnt).BackColor = Color.LightGreen
End If
lab_day(cnt).Text = output
panel_day(cnt).Controls.Ad
'/ CELL
cnt = cnt + 1
Loop
End Sub
You need to declare the Panel List at class level, ie, outside of any routines.
BTW, where are the rest of your variables declared (month_count, monthx, yearx, etc)?
ASKER
Hi there.
Yes the other variables are declared outside any routine.
But if I move this declaration :
Dim month_panel As New List(Of Panel)
out of the routine then I get the error many errors , firstly :
Error 1 'month_panel' is already declared as 'Friend WithEvents month_panel As System.Windows.Forms.Panel ' in this class.
secondly all references to it in the routine now give the error:
Error 3 Class 'System.Windows.Forms.Pane l' cannot be indexed because it has no default property.
Im very confused!
Yes the other variables are declared outside any routine.
But if I move this declaration :
Dim month_panel As New List(Of Panel)
out of the routine then I get the error many errors , firstly :
Error 1 'month_panel' is already declared as 'Friend WithEvents month_panel As System.Windows.Forms.Panel
secondly all references to it in the routine now give the error:
Error 3 Class 'System.Windows.Forms.Pane
Im very confused!
That's easily fixed - rename the Panel List variable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Webtubbs..
Thanks for your help..
I actually just found a reference in the .vb file to a panel that no longer exists in design time.
Friend WithEvents month_panel As System.Windows.Forms.Panel
I deleted this and now it works.
I have also moved the declarations to the class area!
Thanks for your time,
regards
barry
Thanks for your help..
I actually just found a reference in the .vb file to a panel that no longer exists in design time.
Friend WithEvents month_panel As System.Windows.Forms.Panel
I deleted this and now it works.
I have also moved the declarations to the class area!
Thanks for your time,
regards
barry