Question Issue with activation of a databinding

Gualino

Member
Joined
Sep 27, 2011
Messages
10
Programming Experience
Beginner
Hi all,

Let's say we have a controltab with two tab.
The first tab contains textboxs where entry values are entered
On the second tab are textboxs that display the results.
I have noticed that if I fill up the entry values and create the binding between each textbox and their property and then I destroy it (without clearing the textboxs), the textboxs of the second tab will not display any result.

I have this exemple here
BindingAddition.rar

VB.NET:
Public Class Form1

    Public Property Valeur_1 As Double
    Public Property Valeur_2 As Double

    Public ReadOnly Property Resultat As Double
        Get
            Return Addition(Valeur_1, Valeur_2)
        End Get
    End Property

    Public Function Addition(ByVal Valeur1 As Double, ByVal Valeur2 As Double) As Double
        Return Valeur1 + Valeur2
    End Function


    Dim binding_tbox1 As New Binding("Text", Me, "Valeur_1")
    Dim binding_tbox2 As New Binding("Text", Me, "Valeur_2")
    Dim binding_tbox3 As New Binding("Text", Me, "Resultat")
    Private Sub Binding_but_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Binding_but.Click

        binding_tbox1.ControlUpdateMode = ControlUpdateMode.Never
        TextBox1.DataBindings.Add(binding_tbox1)

        binding_tbox2.ControlUpdateMode = ControlUpdateMode.Never
        TextBox2.DataBindings.Add(binding_tbox2)

        TextBox3.DataBindings.Add(binding_tbox3)

        TabPage2.Select()

    End Sub


    Private Sub DestroyBinding_but_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DestroyBinding_but.Click
        TextBox1.DataBindings.Clear()
        TextBox2.DataBindings.Clear()
        TextBox3.DataBindings.Clear()

    End Sub
End Class

I do not know how to solve it.
 
The TabControl (not ControlTab) is designed for efficiency to not create the handles for the controls on each TabPage until the corresponding tab is selected. This can play havoc with bound controls on those TabPages. If you call Show on the TabPage(s) containing bound controls in the Load event handler of the form, that will force the TabPages and their child controls to be created and, therefore, bound. I've seen it said that you should call Hide immediately afterwards but, in my testing, I didn't notice that it made any difference.
 
Thanks jmcilhinney!

I was stuck on that since more than one day.

You are right the show method do not really display the Tab.

"it said" What?, where have you seen what you are talking about?
 
Well it works but it froze the screen in an ugly appearance... I have tried with suspend and resume layout, but it does nothing more. I think it is because this is made to hide controls.

Is there an equivalent of the ScreenUpdating of VBA?
 
I'm afraid I don't know then. I had no issues in my testing, but that was with a very simple form. The only other thing I can suggest is to handle the Shown event of the form and to set the SelectedTab of your TabControl to the second TabPage and then set it back to the first. That will force the controls on that page to be created and bound, but the user may also see it flash up. It's not ideal but it may be your only option, other than not relying on the controls being bound.
 
Back
Top