Hi,

I´m not posting any code - nothing extraordinary - because it is huge and I think a more general reply would be more helpfull for this kind of situation.
I have an object binded to the "Text" property of a textbox and its default-constructor value is "9" . When I change its text it works pretty fine.

    Public Property tenLinh() As String
        Get
            Return tenLin
        End Get
        Set(ByVal value As String)
            tenLin = value
        End Set
    End Property

The variable "value" stands for the text I have entered on the textbox (f. e. 10) and "tenlin" gets the right value (in this case, 10). The problem is when I try to use this new value. For example, the name of my object is "motor". When I try to use the value like: motor.tenLinh, it doesn´t return the correct value, but the old one (in the case, 9). Someone has any idea why this is happening ?

Att,

Ricardo S.

By seeing this code, I assume that you are using a form of data hiding.

That being said, the code posted works and should not create such a problem by its self.

Run a find all references and see where else the value is getting changed for your string.

Hi,

I will add more information about my program, I thought the problem would be easier.
First, I get the properties of my object from a .XML file (I guess I have skiped this part in my previous post) with no problem. When I try to modify the value of motor.tenLinh() using the textbox (let´s say "tenLin" is 110 and I change it to 220 on the textbox), it goes to the class and tenLin really equals to the value 220. The problem occurs when I perform the calculations.
Strangely, Motor.tenLinh() still gets 110. The fun part is when I "try" to change again this property (to 330, for instance). When I get to the part "tenLin = value" just before the instruction runs, the "value" appoints correctly to 330, but tenLin is 220 ???? I really don´t get that, tenLin is being refreshed with no problem, but, when I try to access it through the object, it simply doesn´t work. Has anyone experienced something like that already ?

Thanks,

Ricardo S.

If Motor is the name of the class then you might be refrencing an un instantiated object.

For example:

Dim m As New Motor

'm is now instantiated
m.tenLin = 220

MsgBox(m.tenLin) ' Should read out 220

I hope this helps

Thanks for your support, but the class is classMotor and Motor is the object.

I think the problem might be with how you're binding 'tenlinh' to the textbox and visa-versa. Here's an example of one way that can be done:

Imports System.ComponentModel

    Class Form1
        Dim Motor As New classMotor

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'bind 'tenlinh' to the 'Text' property to reflect any changes made to 'tenlinh'
            TextBox1.DataBindings.Add("Text", Motor, "tenlinh")
        End Sub

        Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
            'this binds any change to the textbox to be reflected in 'tenlinh'
            'the changes are reflected in real time.  To have the change reflected after the input is done you can handle the 'Validated' event
            Motor.tenlinh = TextBox1.Text
        End Sub
    End Class

    Public Class classMotor
        Implements INotifyPropertyChanged
        Private Property tenlin As String = "110"

        Public Sub New()    
        End Sub
        'This notifies the textbox to update the 'Text' proprty.
        Public Event PropertyChanged As PropertyChangedEventHandler _
           Implements INotifyPropertyChanged.PropertyChanged

        Private Sub NotifyPropertyChanged(ByVal info As String)
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
        End Sub

        Public Property tenlinh As String
            Get
                Return tenlin
            End Get
            Set(value As String)
                tenlin = value
                NotifyPropertyChanged("tenlinh")
            End Set
        End Property    
    End Class

With this code any change to either the textbox or 'tenlinh' will be reflected in the other.

Hi,

I´ve got the answer. The problem was that my textbox was inside a tab control and even with all properties being binded correctly, there was a problem when trying to assign a value to the textbox when the tab of the tabcontrol wasn´t the current selected tab - in other words, I was concerned about changing the text on the textbox correctly when the proper tab was selected for the first time and I didn´t thought it would be necessary the second time. I was probably confusing myself with the binding action.

This seems pretty simple, but the thing that really got me into trouble was the fact that, when I was debugging the program, the values of "value" and "tenLin" were really changing to the values I wanted, but they were failing on being refreshed because of the "selected tab problema" - to tell the truth, I still think it is pretty strange.
Thanks for all the help, guys, you all have been really nice !

Att,

Ricardo S.

commented: Awesome! Glad to hear you've found your problem! +8

Glad you have an answer. Please remember to mark this solved thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.