Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,

I want to hide tab page no 3. I am using below code but not works....

VB
Dim cmd As System.Data.SqlClient.SqlCommand
        Dim dr As System.Data.SqlClient.SqlDataReader
        Dim cn As System.Data.SqlClient.SqlConnection
        Try
            cn = New System.Data.SqlClient.SqlConnection(DBset())
            cn.Open()
            cmd = New System.Data.SqlClient.SqlCommand("Select [BackupPath] from Owner", cn)
            dr = cmd.ExecuteReader
            While dr.Read
                bkp_path = dr(0)
            End While
        Catch ex As Exception
        End Try
        dr.Close()
        cn.Close()
        If bkp_path = "No" Then
            TabPage3.Hide()
        Else
            TabPage3.Show()
        End If


Please help me............
Posted
Updated 22-Aug-15 10:37am
v2
Comments
Ralf Meier 22-Aug-15 16:40pm    
And how do you get the bkp_Path ?
Have you checked if it is really on "No" at any time ?
If would suggest that you stop (Exit) your While-Loop if you detect a "No" in it. In this case it could work ...
hspl 23-Aug-15 3:58am    
Sir,

I made a declaration that
Dim bkp_path as String in form
And by default bkp_path = No which i read from database
Ralf Meier 23-Aug-15 14:47pm    
I understand ...
But you haven't understand what I meant ... sorry ...
You have a While-Loop :
While dr.Read
bkp_path = dr(0)
End While
What do you do, if the first Read gets a "No" and the second (and each other) gets a "Yes" ...?
hspl 23-Aug-15 23:30pm    
sir
if second gets a path name(eg:D:\Pms) not No
Ralf Meier 24-Aug-15 0:43am    
OK ... but if the first one (or any other) has got a "Yes" you want to have the TabPage invisible ?

This would seem like a straight forward Visible = True or False situation. I use TabControls regularly, but I have to say I have never come across a situation where I needed to hide a TabPage(make it not visible).
The Property Visible is not meaningful for this control (this is straight from MSDN). Although in DEBUG mode you can see this property in the object tree (but it is set to FALSE no matter what). The property Hide only hides the controls on the specified TabPage, not the TabPage itself. If you Hide the TabPage the controls will be hidden, interestingly, if you move from that page and then move back to the TabPage that invoked .Hide(), the controls will then be visible.
I believe the only way to facilitate "visible/non-visible" is by removing the TabPage from the TabPages collection when you need to make it not visible and then adding it back in when the TabPage is to be visible.
The link below has a solution that should give you a good starting point – you will need to manage the remove/add activities with some additional code.

https://social.msdn.microsoft.com/Forums/windows/en-US/89053adf-7875-4db9-b328-460a7b1f97c0/how-to-remove-hide-tabpage-from-a-tabcontrol-using-vb-net-c-net

The following is a suggestion, moving TabPages between two or more TabControls to maintain the original collect isn't necessary. And the design considerations given below in Solution 2 do address some of the problems you face. To solve the specific problem you state without questioning the objective I would do something similar to the following code. Note this has the mechanism to remove-store and add-back. The DOUBLECLICK method is used for demo purposes. You can add this to your project, rebuilt, add the control to a form and explore.

Public Class MyTabControl
    Inherits TabControl

#Region "DELEGATES_EVENTS"
    Public Event HasError(ByVal sender As Object, ByVal e As EventArgs)
#End Region

#Region "VARS"
    Dim RemoveTabs As List(Of TabPage)
    Dim _lastRemoveException As Exception
#End Region

#Region "CONSTRUCTORS_DESTRUCTORS"
    Public Sub New()
        RemoveTabs = New List(Of TabPage)
    End Sub
#End Region

#Region "SUBS_FUNCS"
    Private Sub OnError(ByVal e As Exception)
        _lastRemoveException = e
        RaiseEvent HasError(Me, EventArgs.Empty)
    End Sub
    Public Function GetLastExcceptio() As Exception
        Return _lastRemoveException
    End Function
    Public Function RemoveCurrentTab(ByVal tp As TabPage) As Boolean
        Dim result As Boolean
        Try
            TabPages.Remove(tp)
            RemoveTabs.Add(tp)
            result = True
        Catch ex As Exception
            OnError(ex)
        End Try
        Return result
    End Function
    Public Function AddTabBack(ByVal title As String) As Boolean
        Dim result As Boolean
        Try
            If Not String.IsNullOrEmpty(title) Then
                For Each tp As TabPage In RemoveTabs
                    If String.Compare(tp.Text, title) = 0 Then
                        RemoveTabs.Remove(tp)
                        TabPages.Add(tp)
                        result = True
                        Exit For
                    End If
                Next
            End If
        Catch ex As Exception
            OnError(ex)
        End Try
        Return result
    End Function
#End Region

#Region "CONTROL_EVENTS"
    Private Sub MyTabControl_DoubleClick(sender As Object, e As EventArgs) Handles Me.DoubleClick
        RemoveCurrentTab(Me.SelectedTab)
    End Sub
#End Region

End Class


regs
ron O.
 
Share this answer
 
v2
MSDN wrote:
Remarks

This member is not meaningful for this control.

To hide a tab in a TabControl, you must remove it from the control's TabPages collection.

Source: TabPage.Visible Property [^]

So, some members recommend very ugly solution for this, where two TabControls are placed on the same form and TabPages are moved between them.
Note: I do NOT recommend this. Rather then it, follow these links:
Wizards[^]
Wizards: Design Guidelines[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900