Entity values not updates when using binding to textbox

Posts   
 
    
Pteranodon
User
Posts: 7
Joined: 21-Dec-2012
# Posted on: 21-Dec-2012 12:50:56   

Greetings,

I have a vb.net application, which has a textbox (textbox1). I am trying to use the databindings of this textbox to bind it to an entity, created with llblgen. The data is shown in the textbox normally, but when I try to change this data, is jumps back to the initial data when I change focus to another object.

I am using the following code:

   Private Sub setDataLoggerBindings()
        ' DataLogger bindings
        With frmEquipment.GlobalForm
            If .selEntity.DataLogger_.Count > 0 Then
                Me.TextBox1.DataBindings.Clear()
                Dim b As New Binding("Text", .selEntity.DataLogger_(0), "MachineNumber")
                Me.Textbox1.DataBindings.Add(b)
            End If
        End With
    End Sub

Is there some setting I need to adjust to be able to get the value to the entity?

I am using the following setup: version: LLBLGen Pro 2.6 Final (October 6th, 2008 ) (no specific buildnr is mentioned) runTime library version: 2.6.9.116 Template group: SelfServicing Target language: VB.NET 3.5 Database: Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
Nov 24 2008 13:01:59
Copyright (c) 1988-2005 Microsoft Corporation
Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

selEntity is an entity base on a record of the table Equipment, which has the following structure:

CREATE TABLE [dbo].[Equipment](
    [EquipmentID] [int] IDENTITY(0,1) NOT NULL,
    [DataLogger] [bit] NULL CONSTRAINT [DF_Equipment_DataLogger]  DEFAULT ((0)),
    [MainEquipment] [int] NULL CONSTRAINT [DF_Equipment_MainEquipment]  DEFAULT ((0)),
 CONSTRAINT [PK_Equipment] PRIMARY KEY CLUSTERED 
(
    [EquipmentID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[Equipment]  WITH CHECK ADD  CONSTRAINT [FK_Equipment_Equipment] FOREIGN KEY([MainEquipment])
REFERENCES [dbo].[Equipment] ([EquipmentID])
GO
ALTER TABLE [dbo].[Equipment] CHECK CONSTRAINT [FK_Equipment_Equipment]

datalogger(0)_ is an entity based on a record of the table DataLogger, which has the following structure:

CREATE TABLE [dbo].[DataLogger](
    [DataLoggerID] [int] IDENTITY(0,1) NOT NULL,
    [EquipmentID] [int] NULL,
    [MachineNumber] [int] NULL,
 CONSTRAINT [PK_Machine] PRIMARY KEY CLUSTERED 
(
    [DataLoggerID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[DataLogger]  WITH CHECK ADD  CONSTRAINT [FK_Machine_Equipment] FOREIGN KEY([EquipmentID])
REFERENCES [dbo].[Equipment] ([EquipmentID])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DataLogger] CHECK CONSTRAINT [FK_Machine_Equipment]
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 21-Dec-2012 15:43:33   

Could you please download the latest v2.6 build from the customer area? Your build is 2.6.9.116, which is from January 16th, 2009. This, to rule out any bugfixes which might affect your problem. Also could you confirm this is winforms? This isn't clear from your code.

Frans Bouma | Lead developer LLBLGen Pro
Pteranodon
User
Posts: 7
Joined: 21-Dec-2012
# Posted on: 02-Jan-2013 12:50:04   

The form is indeed an instance of the class System.Windows.Forms.Form. Can you point me where I can download the latest version v2.6 build?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 02-Jan-2013 18:39:34   

Pteranodon wrote:

The form is indeed an instance of the class System.Windows.Forms.Form. Can you point me where I can download the latest version v2.6 build?

From the customer area: log in with your customerid & password, then at the left click 'v2.6' and download the latest build.

However, it might very well be a windows forms thing. please try another overload of the constructor of Binding, namely the one where you can specify DataSourceUpdateMode. See documentation of the Binding class in MSDN for details.

Frans Bouma | Lead developer LLBLGen Pro
Pteranodon
User
Posts: 7
Joined: 21-Dec-2012
# Posted on: 10-Jan-2013 11:12:15   

Otis wrote:

However, it might very well be a windows forms thing. please try another overload of the constructor of Binding, namely the one where you can specify DataSourceUpdateMode. See documentation of the Binding class in MSDN for details.

I have tried the following code:

Private Sub setDataLoggerBindings()
      ' DataLogger bindings
      With frmEquipment.GlobalForm
         If .selEntity.DataLogger_.Count > 0 Then
            Me.TextBox1.DataBindings.Clear()
            Dim b As New Binding("Text", .selEntity.DataLogger_(0), "MachineNumber")
            b.DataSourceUpdateMode = DataSourceUpdateMode.OnValidation
            Me.Textbox1.DataBindings.Add(b)
         End If
      End With
End Sub

This did not make any difference. Also OnPropertyChanged for DataSourceUpdateMode did not make any difference.

I tried the example code MSDN Binding Class and this works like a charm. However, this does not make use of a connection to SQL. But it makes me believe the issue is not generated by the vb components.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 10-Jan-2013 17:18:01   

Please set a breakpoint on the Set part of the property in the entity class you're changing through binding and check whether it gets actually called.

Frans Bouma | Lead developer LLBLGen Pro
Pteranodon
User
Posts: 7
Joined: 21-Dec-2012
# Posted on: 11-Jan-2013 11:26:18   

Otis wrote:

Please set a breakpoint on the Set part of the property in the entity class you're changing through binding and check whether it gets actually called.

The set part does not get triggered, the get part does get triggered though. So I tried to check if the binding is detecting the change properly, by changing the code to:

Private Sub setDataLoggerBindings()
      ' DataLogger bindings
      With frmEquipment.GlobalForm
         If .selEntity.DataLogger_.Count > 0 Then
            Me.TextBox1.DataBindings.Clear()
            Dim b As New Binding("Text", .selEntity.DataLogger_(0), "MachineNumber")
            AddHandler b.Parse, AddressOf parse1
            Me.Textbox1.DataBindings.Add(b)
         End If
      End With
End Sub

private sub parse1(byval sender as object, byval cevent as ConvertEventArgs)
    MsgBox("Value = " + cevent.Value))
end sub

Then the messagebox shows the changed value, but after pressing the "OK" button, the value of the textbox jumps back to the initial value.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jan-2013 13:35:36   

Did you download and use the latest build of v.2.6? Please do so, to eliminate this possibility.

Pteranodon
User
Posts: 7
Joined: 21-Dec-2012
# Posted on: 11-Jan-2013 15:00:18   

The problem was that the value coming from the textbox was of type System.Int32, while the desired type was nullable (Of System.Int32). The issue was solved by enabling the FormattingEnabled property of the binding:

Private Sub setDataLoggerBindings()
      ' DataLogger bindings
      With frmEquipment.GlobalForm
         If .selEntity.DataLogger_.Count > 0 Then
            Me.TextBox1.DataBindings.Clear()
            Dim b As New Binding("Text", .selEntity.DataLogger_(0), "MachineNumber")
            b.FormattingEnabled = true
            Me.Textbox1.DataBindings.Add(b)
         End If
      End With
End Sub

Thanks for helping me solve this issue.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 11-Jan-2013 18:37:55   

Ah! insane isn't it, these silly binding settings which may or may not make the binding succeed, but there's no exception/feedback given by the winforms binding code, it's pure trial/error. Glad it's solved simple_smile

Frans Bouma | Lead developer LLBLGen Pro