Databinding not working when accessing Toolbar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Pressing a Save Button on a Toolbar will not bind or validate the last value entered in a text box.

I have found that when clicking on the Toolbar the focus in the binded text box does not leave. Therefore in this case not saving the last entry when saving.
I am able to use the following code to get round the updating of the object from the field value with this code before saving

Private m_Record As Customer

.......

Private Sub TopToolBar_ToolClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles TopToolBar.ToolClick

'Ensure last value has been placed into the object
Me.BindingContext(m_Record).EndCurrentEdit()

SetCustomer(m_Record)

End Sub

however my validating method on the field needs to run on the field before saving.

Has anyone got an elequent way of successfully validating and binding a value before pressing the save button on a toolbar.

Thank you in advance

Stewart
 
Hi Stewart,

The value doesn’t get selected until you hit the Enter key or the TextBox control loses focus. The TextBox doesn’t lose focus when you hit the save button in a control that doesn’t take the focus like a toolbar. You would need to call the Focus method of the Toolbar that has been clicked to force the selection of the new value.

HTH,

Michael
 
Stewart,

If you have the entire contents in memory you can save it to a temporary
file and load XML. If you have each individual values then you can use the
Automation to populate the values in to the Excel worksheet.

Best Regards,
Y. Sivaram

Stewart said:
Pressing a Save Button on a Toolbar will not bind or validate the last value entered in a text box.

I have found that when clicking on the Toolbar the focus in the binded
text box does not leave. Therefore in this case not saving the last entry
when saving.
I am able to use the following code to get round the updating of the
object from the field value with this code before saving
Private m_Record As Customer

......

Private Sub TopToolBar_ToolClick(ByVal sender As System.Object, ByVal e As
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles
TopToolBar.ToolClick
'Ensure last value has been placed into the object
Me.BindingContext(m_Record).EndCurrentEdit()

SetCustomer(m_Record)

End Sub

however my validating method on the field needs to run on the field before saving.

Has anyone got an elequent way of successfully validating and binding a
value before pressing the save button on a toolbar.
 
OK Stewart,

** You use a 3rd-party Control, namely Infragistics. So normally you would pop the question there..... **

Private Sub TopToolBar_ToolClick(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles TopToolBar.ToolClick
TopToolBar.Focus()

' Your code
................
End Sub

Doing so Forces the TextBox to Raise the Validating (and ultimatly Validated) Event. This is, of course, for TextBoxBase-Derived TexBoxes. I don't know what Infragistics uses, but I gues they Derived from TbBase.

If you Trigger your Validation-Code through the TextBox.Validating-Event, then this Has to work.

.......

Unless I misunderstood your issue.

Regards,

Michael
 
Stewart,
You can use Form.Validate (inherited from ContainerControl) to valid the
"last invalidated control and its ancestors up through, but not including,
the current control".
Private Sub TopToolBar_ToolClick(ByVal sender As System.Object, ByVal e As
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles
TopToolBar.ToolClickIf Me.Validate Then
'Ensure last value has been placed into the object
Me.BindingContext(m_Record).EndCurrentEdit()

SetCustomer(m_Record)

End If

I got the following tip from "Windows Forms Programming in C#" by Chris
Sells, from Addison Wesley.

Within your "Accept" button click handler ("save" button) process each
control that CausesValidation to ensure that they are all valid...

Something like:

For Each control As control In Me.Controls
If control.CausesValidation Then
control.Focus()
If Not Me.Validate() Then
Me.DialogResult = DialogResult.None
Exit For
End If
End If
Next

Note this version does not validate controls nested within other container
controls, such as GroupBoxes...

Hope this helps
Jay

Stewart said:
Pressing a Save Button on a Toolbar will not bind or validate the last value entered in a text box.

I have found that when clicking on the Toolbar the focus in the binded
text box does not leave. Therefore in this case not saving the last entry
when saving.
I am able to use the following code to get round the updating of the
object from the field value with this code before saving
Private m_Record As Customer

......

Private Sub TopToolBar_ToolClick(ByVal sender As System.Object, ByVal e As
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles
TopToolBar.ToolClick
'Ensure last value has been placed into the object
Me.BindingContext(m_Record).EndCurrentEdit()

SetCustomer(m_Record)

End Sub

however my validating method on the field needs to run on the field before saving.

Has anyone got an elequent way of successfully validating and binding a
value before pressing the save button on a toolbar.
 
Back
Top