Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Vfp .net event equivalent
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01489449
Message ID:
01490021
Views:
27
>>>Here's the code for what that's worth:
>>>
>>>    Sub BindingFormat() Implements IControlBindingFormat.BindingFormat
>>>        Dim B As Binding = Me.DataBindings.Item(0)
>>>        AddHandler B.Format, AddressOf BooleanToJaNeen
>>>        AddHandler B.Parse, AddressOf JaneenToBoolean
>>>    End Sub
>>>    Sub BooleanToJaNeen(ByVal sender As Object, ByVal cEvent As ConvertEventArgs)
>>>        If cEvent.Value Is System.DBNull.Value Then
>>>            cEvent.Value = ""
>>>            Exit Sub
>>>        End If
>>>        cEvent.Value = IIf(cEvent.Value, "Ja", "Neen")
>>>    End Sub
>>>    Sub JaneenToBoolean(ByVal sender As Object, ByVal cEvent As ConvertEventArgs)
>>>        cEvent.Value = IIf(cEvent.Value = "Ja", True, False)
>>>    End Sub
>>>
>>
>>I see Bonny has pointed out one possible cause but I get the impression it's a more general problem (i.e. not related to the control not losing focus) ?
>>IAC I don't see anything wrong in the code above (assuming that any entry other than "JA" translating to false is the expected behaviour). Bear in mind that it would be normal behaviour for the Format event to fire after the Parse (the data is round-tripped). The fact that it is firing at all seems to indicate something is happening.
>
>Well I traced things, and you're right, the format event seems to be fired after the parse event when I issue the bindingsource.endedit. The problem is that the dataset seems to have the original value, whereas on screen I see the new one before bindingsource.endedit ... and the old one after it (which I understand as the format event applied to the original bindingsource value).
>
>I also checked whether or not the validating event is fired, it definitely is. And the binding.parse event is not fired.
>
>Let me see if I got things straight conceptually. I was hoping to have this base class comboboxJaNeen (Ja= yes, Neen = no, but I guess you had gathered that already). I wanted to use it for fields in the datastore that are defined as booolean. On screen I wanted to represent such fields in my comboboxJaNeen class. I was hoping that the format event would translate the boolean into Ja for true and No for false, which seems to work neatly. By analogy, I was hoping that the Parse event would be fired whenever there is a need to synchronize between what's on screen in the ctl.text property and whatever gets stored in bindingsource's dataset. I understand now the latter happens at validating time, which is fine by me.
>
>Thanks for bearing with me.

Here, AFAICS, is a form with a bare bones version of that you are trying to achieve:
Imports System.ComponentModel

Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    Private m_isItTrue As Boolean
    Public Property IsItTrue() As Boolean
        Get
            System.Diagnostics.Trace.WriteLine("Getting :" + m_isItTrue.ToString())
            Return m_isItTrue
        End Get
        Set(ByVal value As Boolean)
            System.Diagnostics.Trace.WriteLine("Setting :" + value.ToString())
            m_isItTrue = value
        End Set
    End Property

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        TextBox1.Location = New System.Drawing.Point(100, 100)
         TextBox1.Size = New System.Drawing.Size(100, 20)
        TextBox1.CausesValidation = True
        Me.Controls.Add(TextBox1)

        Dim B As Binding = New Binding("Text", Me, "IsItTrue")
        AddHandler B.Format, AddressOf BooleanToJaNeen
        AddHandler B.Parse, AddressOf JaneenToBoolean
        TextBox1.DataBindings.Add(B)

        Me.Controls.Add(New Button) 'Just to allow focus to move
    End Sub

    Private Sub HandleValidating(ByVal sender As Object, ByVal e As CancelEventArgs) Handles TextBox1.Validating
        System.Diagnostics.Trace.WriteLine("Validating")
    End Sub

    Private Sub HandleValidated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
        System.Diagnostics.Trace.WriteLine("Validated")
    End Sub

    Sub BooleanToJaNeen(ByVal sender As Object, ByVal cEvent As ConvertEventArgs)
        If cEvent.Value Is System.DBNull.Value Then
            cEvent.Value = ""
            Exit Sub
        End If
        cEvent.Value = IIf(cEvent.Value, "Ja", "Neen")
        System.Diagnostics.Trace.WriteLine("Format to: " + cEvent.Value.ToString())
    End Sub

    Sub JaneenToBoolean(ByVal sender As Object, ByVal cEvent As ConvertEventArgs)
        cEvent.Value = IIf(cEvent.Value = "Ja", True, False)
        System.Diagnostics.Trace.WriteLine("Parse to: " + cEvent.Value.ToString())
    End Sub

End Class
Try running this and check the Output window. Where does your form behaviour differ ?
Previous
Reply
Map
View

Click here to load this message in the networking platform