LeighWardle
asked on
How to refresh DataGridView column layout
Hi Experts,
I have a DataGridView component that is visible no matter which Tab Page is selected on a Tab control.
The code below shows how I am attempting to make various columns Hidden/Visible depending on which Tab is clicked.
But the columns aren't changing.
What Method do I need to update the column layout?
Regards,
Leigh
Regards,
Leigh
I have a DataGridView component that is visible no matter which Tab Page is selected on a Tab control.
The code below shows how I am attempting to make various columns Hidden/Visible depending on which Tab is clicked.
But the columns aren't changing.
What Method do I need to update the column layout?
Regards,
Leigh
Private Sub tabControl_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles tabControl.SelectedIndexChanged
' Move the DataGridView to the Current Tab:
tabControl.TabPages(tabControl.SelectedIndex).Controls.Add(dgvMaterials)
' Change the DataGridView somehow:
Select Case tabControl.SelectedIndex
Case 0
' configure the columns for "Properties" tab
'Hide superfluous columns (20120918)
Me.dgvMaterials.Columns("sglCostPerVolume").Visible = False
Me.dgvMaterials.Columns("sglCostPerArea").Visible = False
Me.dgvMaterials.Columns("sglCostPerWeight").Visible = False
Me.dgvMaterials.Columns("sglWeightPerVolume").Visible = False
Case 1
' configure the columns for "Costs" tab
'Hide superfluous columns (20120918)
Me.dgvMaterials.Columns("Modulus1").Visible = True
Me.dgvMaterials.Columns("Poissons1").Visible = True
Me.dgvMaterials.Columns("Modulus2").Visible = True
Me.dgvMaterials.Columns("Poissons2").Visible = True
Me.dgvMaterials.Columns("ShearModF").Visible = True
'Expose previously hidden columns (20120918)
Me.dgvMaterials.Columns("sglCostPerVolume").Visible = True
Me.dgvMaterials.Columns("sglCostPerArea").Visible = True
Me.dgvMaterials.Columns("sglCostPerWeight").Visible = True
Me.dgvMaterials.Columns("sglWeightPerVolume").Visible = True
Case 2
' configure the columns for tab 2
End Select
End Sub
Regards,
Leigh
ASKER
Sorry, ashokpumca, I looked through your suggested links - I cannot find a solution.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, CodeCruiser.
When I stepped through the code I realized I had some True's and False's mixed up.
The corrected code works without calling the Refresh method of the grid at the end.
When I stepped through the code I realized I had some True's and False's mixed up.
The corrected code works without calling the Refresh method of the grid at the end.
Just go through the links below : Show / Hide GridView Columns in ASP.NET
1. http://www.codeproject.com/Articles/43727/Show-Hide-GridView-Columns-in-ASP-NET
2. http://ramanisandeep.net/2009/04/07/how-to-hide-gridview-column-programmatically/