Data Binding Text Boxes

Data Binding Text Boxes

Old forum URL: forums.lhotka.net/forums/t/1386.aspx


Brownpa1 posted on Wednesday, October 04, 2006

I have a HardwareBindingSource that I set all my textboxes on my form to under the  DataBindings Text property.

I cannot get my text boxes on my windows form to update after I make a change in a text box and apply that change to update all the other textboxes which  I am making changes to inside my Hardware object for example when I do an update I automatically update the LastUpdated property to the current date and the LastUpdatedUserID to the current logged on user.  However, my form is not reflecting this change. 

I am rebinding my Datasource to reflect the changes and I also added the BindingSourceRefresh Control onto my form as suggested in the Expert VB 2005 Business Objects book, however my databind is still not working.  When I step through my Hardware object, it appears that all my changes are being made, however when my form pops back up the update does not reflect these changes.  However, if I close my form and reopen it to that hardware object the changes are reflected.

Does anybody have any ideas on what I am missing here?  Thank you in advance for your help.

 

Brian Criswell replied on Wednesday, October 04, 2006

Could you show us the code to one of your properties that you are updating?

Brownpa1 replied on Wednesday, October 04, 2006

I think I have it working, however I'm new to vb.net 2005 and csla 2.0 and not sure if this is going to cause other problems.  I moved the code below that is hightlighted in yellow from under the Temp.ApplyEdit into the Finally in my try/catch after the RaiseListChangedEvents = True  and it now seems to be rebinding my text boxes with the new data.   Can you tell me if this is the correct way to be doing this?   My user hit the Apply button on the form and the below code runs.

Private Sub SaveHardware(ByVal blnRebind As Boolean)

Me.Cursor = Cursors.WaitCursor
Me.HardwareBindingSource.RaiseListChangedEvents = False

'do the save
Dim temp As COLibrary.Hardware = m_Hardware.Clone
temp.ApplyEdit()

Try
   m_Hardware = temp.Save
   m_Hardware.BeginEdit()
Catch ex As Csla.DataPortalException
   MessageBox.Show(ex.BusinessException.ToString,
"Error saving", _
   MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception
   MessageBox.Show(ex.ToString,
"Error saving", _
   MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Finally

Me.HardwareBindingSource.RaiseListChangedEvents = True

If blnRebind Then
   'rebind the UI
   'Me.HardwareBindingSource.DataSource = Nothing
   Me
.HardwareBindingSource.DataSource = m_Hardware
End If

End Try

End Sub

Brian Criswell replied on Wednesday, October 04, 2006

I think that possibly your method should look more like this.

Private Sub SaveHardware(ByVal blnRebind As Boolean)
    Try
        Me
.Cursor = Cursors.WaitCursor
       
HardwareBindingSource.EndEdit()
        m_Hardware = m_Hardware.Clone().Save()
        If blnRebind Then HardwareBindingSource.DataSource = m_Hardware
    Catch ex As Csla.DataPortalException
        MessageBox.Show(ex.BusinessException.ToString,
"Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Catch ex As Exception
        MessageBox.Show(ex.ToString,
"Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    End
Try
End
Sub

Do you want your updated date and user updated after a property change or after a save?

Brownpa1 replied on Thursday, October 05, 2006

I want the updated date and user updated after a save.  The above code seems to works great.  I'm still in learning mode so I'm somewhat confused on what some of this code actually does.  Thank you for your time.

Brian Criswell replied on Thursday, October 05, 2006

Private Sub SaveHardware(ByVal blnRebind As Boolean)
    Try
        Me
.Cursor = Cursors.WaitCursor
       
HardwareBindingSource.EndEdit()   '  Forces binding to push any last changes into the object and accepts the changes
        m_Hardware = m_Hardware.Clone().Save()   ' Clones the object and attempts to save the clone overwriting the reference if successful
        If blnRebind Then HardwareBindingSource.DataSource = m_Hardware   '  Updates the data binding (probably should always be done)
    Catch ex As Csla.DataPortalException
        MessageBox.Show(ex.BusinessException.ToString,
"Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Catch ex As Exception
        MessageBox.Show(ex.ToString,
"Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    End
Try
End
Sub

Copyright (c) Marimer LLC