myriam myriam - 1 year ago 82 Question

Display two different Grids in the same form not at the same time

I have two different Gridviews that I have to display in the same form but not at the same time. Display

when the user presses
when they press

How can this be achieved?

Answer Source

If this is a WinForms application then I suggest to put both grids on your form designer surface, with a minimum size to be operable, one of the two grids will have its Visible property set initially to False. Also put your buttons on the form inside a panel and dock the panel to the bottom of your form.

When the code enters the form constructor apply the Dock = DockStyle.Fill to both grids and change the Visible property of the two grids at the button click

Public Sub New()
    grid1.Dock = DockStyle.Fill
    grid2.Dock = DockStyle.Fill   ' This has the Visible = False
End Sub

Public Sub button1_Click(sender as Object, e as EventArgs)
     grid1.Visible = False
     grid2.Visible = True


Public Sub button2_Click(sender as Object, e as EventArgs)
     grid1.Visible = True
     grid2.Visible = False
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download