Remove all Dynamical Tab Page From Tabcontrol at Runtime

goharynet

New member
Joined
Aug 20, 2008
Messages
4
Programming Experience
Beginner
I have Win Form With Tab Control , and at run time i Create many Dynamically Tab Page with many child control
i put the code to create this Tab Page in Activated event of the form to update the Tab Page when the form will be active
but when the form be activate the tab page duplicated
i use
tabcontrol.tabpage.clear()

before create Dynamically Tab Page but it make error

now how i can prevent this duplication in every time the form be active?
thanks
 
You haven't given us much to go on, i.e. that's a very vague description of what you're trying to achieve, but at the very least it sounds like the Activated event is a poor choice. Surely you don't want to be adding TabPages every tine the form receives focus. Maybe it would make sense to add the TabPages only once, e.g. in the Load event handler, and then just refresh the data they contain on the Activated event. Maybe if you provided a FULL and CLEAR explanation of what you're trying to achieve then we could be more specific but that seems a logical way to do things.
 
i use this code to create dynamically tab page
i put it in form load .. in first opening of form the code work good
but if i close the form and open it again
i find duplication in the tab page number
how i can prevent this duplication ?



For Ti = 1 To 5

If GSQLConnection.State = ConnectionState.Open Then GSQLConnection.Close()
Dim Adp As SqlClient.SqlDataAdapter

'On Error Resume Next
Dim strsql As String = "SELECT " & _
"TabPageID,TabPageText " & _
" FROM " & _
"FastSalesTabPage " & _
"WHERE POSID= '" & My.Settings.CurrentSOPID & "' AND TabPageID='" & Ti & "'"

GSQLConnection.Open()
Dim ds2 As New DataSet
Adp = New SqlClient.SqlDataAdapter(strsql, GSQLConnection)
ds2.Clear()
Adp.Fill(ds2)
If ds2.Tables(0).Rows.Count > 0 Then

Dim TapPage As DevExpress.XtraTab.XtraTabPage

TapPage = XtraTabControl1.TabPages.Add(ds2.Tables(0).Rows(0).Item(1))
TapPage.Name = ds2.Tables(0).Rows(0).Item(0)


End If

GSQLConnection.Close()

Next
 
how i can prevent this duplication ?

Isn't the answer obvious? You wouldn't be asking this question if this was a physical task because the answer would be obvious: you simply look to see whether the task has already been done and, if it has, you don't do it again. Why would the answer be any different here? You simply check whether there are already TabPages there and, if there are, you don't add any new ones.
 
Back
Top