Index Of Panels

Joined
Jul 30, 2006
Messages
10
Programming Experience
1-3
For my program i have different panels containing data. Wat i tried to do was when the panel was focused (or clicked/brought to front) the following code would execute

currentpanel = Me.Controls.IndexOf(sender)

'Sender bieng the panel control

the problem is that these panels are created at run time, and they all have an index of 0 according to the value returned by that.... :confused:

is there a different way to get the index of these controls, or do created controls use the same index in vb.net? the code to create them is:

DO
Dim newpanel As New Panel
'SETS PROPERTIES
me.controls.add(newpanel)
i += 1
LOOP until i = My.Settings.NumberOfItems

so basically i need each panel to have a unique index :p

Thanks!
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,726
Location
Sydney, Australia
Programming Experience
10+
VB.NET:
Private panels As Panel()

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.panels = New Panel([U]My.Settings.NumberOfItems[/U] - 1) {}

    Dim newPanel As Panel

    For index As Integer = 0 To Me.panels.GetUpperBound(0) Step 1
        newPanel = New Panel
        Me.panels(index) = newPanel
        Me.Controls.Add(newPanel)
    Next index
End Sub
Now you refer to them via their index in the 'panels' array.
 
Joined
Jul 30, 2006
Messages
10
Programming Experience
1-3
Showing

Yeh thats cool, i picked that bit up :p

just wondering how you would go about showing these panels and getting thier index based on the sender control

i tried using

Me.Panels(1).visible = true

and i changed many other properties, but it didnt show up!
 
Top Bottom