Easy question...(I think) 
Author Message
 Easy question...(I think)

I'm trying to create a listbox where a click on each entry should unhide a
different panel, while hiding all the others. There are a lot of different
entries in the listbox (and thus alot of different panels); the way I did it
is really time consuming:

Dim SelectedEntry

If SelectedEntry = "0" Then

Panel1.Show()

Panel2.Hide()

Panel3.Hide()

Panel4.Hide()

Panel5.Hide()

Panel6.Hide()

Etc....

Is there a shortcut to hide all other panels at once instead of hiding each
panel seperatly?

Thanx alot!



Sat, 25 Jun 2005 06:12:29 GMT  
 Easy question...(I think)
Hi Christophe:

Have you thought about using a Control array for the Panels?
That way, you could do this very easily in a loop:

Dim pnl As Panel
For Each pnl In Panels
   If pnl.Index = SelectedEntry Then
      pnl.Show
   Else
      pnl.Hide
   End If
Next pnl

Hope this helps,

Doug.

Quote:
> I'm trying to create a listbox where a click on each entry should unhide a
> different panel, while hiding all the others. There are a lot of different
> entries in the listbox (and thus alot of different panels); the way I did it
> is really time consuming:

> Dim SelectedEntry

> If SelectedEntry = "0" Then

> Panel1.Show()

> Panel2.Hide()

> Panel3.Hide()

> Panel4.Hide()

> Panel5.Hide()

> Panel6.Hide()

> Etc....

> Is there a shortcut to hide all other panels at once instead of hiding each
> panel seperatly?

> Thanx alot!



Sat, 25 Jun 2005 06:32:44 GMT  
 Easy question...(I think)
If you convert those "Panel" controls into a control array, the following should help...
'==========
Option Explicit

Private Sub List1_Click()
   Dim SelectedEntry As Integer
   Dim i As Integer

   SelectedEntry = List1.ListIndex

   'Hide all except the currently selected "Panel"
   For i = 0 To List1.ListCount - 1
      Panel1(i).Visible = (i = SelectedEntry)
   Next
End Sub
'==========

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com - Please keep it in the groups..


Quote:
> I'm trying to create a listbox where a click on each entry should unhide a
> different panel, while hiding all the others. There are a lot of different
> entries in the listbox (and thus alot of different panels); the way I did it
> is really time consuming:

> Dim SelectedEntry

> If SelectedEntry = "0" Then

> Panel1.Show()

> Panel2.Hide()

> Panel3.Hide()

> Panel4.Hide()

> Panel5.Hide()

> Panel6.Hide()

> Etc....

> Is there a shortcut to hide all other panels at once instead of hiding each
> panel seperatly?

> Thanx alot!



Sat, 25 Jun 2005 06:26:10 GMT  
 Easy question...(I think)
That seems like a great idea!
Could you please explain me (in brief) how to create an array which contains
(for example) Panel1, Panel2 and Panel3?

Thanx!

Christophe



Quote:
> Hi Christophe:

> Have you thought about using a Control array for the Panels?
> That way, you could do this very easily in a loop:

> Dim pnl As Panel
> For Each pnl In Panels
>    If pnl.Index = SelectedEntry Then
>       pnl.Show
>    Else
>       pnl.Hide
>    End If
> Next pnl

> Hope this helps,

> Doug.

> > I'm trying to create a listbox where a click on each entry should unhide
a
> > different panel, while hiding all the others. There are a lot of
different
> > entries in the listbox (and thus alot of different panels); the way I
did it
> > is really time consuming:

> > Dim SelectedEntry

> > If SelectedEntry = "0" Then

> > Panel1.Show()

> > Panel2.Hide()

> > Panel3.Hide()

> > Panel4.Hide()

> > Panel5.Hide()

> > Panel6.Hide()

> > Etc....

> > Is there a shortcut to hide all other panels at once instead of hiding
each
> > panel seperatly?

> > Thanx alot!



Sat, 25 Jun 2005 07:00:54 GMT  
 Easy question...(I think)

Quote:
> That seems like a great idea!
> Could you please explain me (in brief) how to create an array which
> contains (for example) Panel1, Panel2 and Panel3?

Since you already have them, select Panel1 on the form in design mode and
set the Index property to 0.  Then select Panel2 and change the Name
property to Panel1 -- if it asks if you want a control array say yes but it
should assume that you do and automatically make the Index property 1.
Change the name for Panel2, Panel3, etc

To create a new control array in the future, draw the first element on the
form then copy it and paste a second one.  VB will ask if you want a control
array.



Sat, 25 Jun 2005 08:18:44 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Easy question (I think)

2. TreeView Nodes: Easy question I think,

3. Easy Question (I think)

4. Easy Question (I think)

5. Easy Question...........I Think

6. easy question (i think)

7. Easy question..I think

8. Easy question, I think - Can you Debug.Print at runtime (not in IDE)?

9. Easy ADO Question (I Think)

10. EASY EASY EASY question

11. Really easy I think

12. I thought this would be easy!

 

 
Powered by phpBB® Forum Software