Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Interesting Update Sequence in NumericUpDown DataBinding
 

Interesting Update Sequence in NumericUpDown DataBinding

Well,

I do believe this is reciprocatable, but maybe my system is just wacky like this.

NumericUpdown on a form, with a DataSet, TableAdapter, and BindingSource

Bind the Value property of the NumericUpDown to a numeric (integer or float, mine is currently a money type in the DB (decimal interpreted by VS))

Frist, unlike other controls, or should I say unlike the DataGridView, I have to specifically call the BindSource.EndEdit() to get the changes to reflect upon the DataSet.HasChanges() which is fine, I don't mind that one bit, but the process is strange:

      Me.ud_WWriteOff.DataBindings.Add(New System.Windows.Forms.Binding("Value", Me.bind_InvWood, "WriteOff", True, DataSourceUpdateMode.OnValidation, 0.0, "C2"))

      Me.ud_PWriteOff.DataBindings.Add(New System.Windows.Forms.Binding("Value", Me.bind_InvPlastic, "WriteOff", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, 0.0, "C2"))


   Private Sub UpDown_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles ud_PWriteOff.Validated, ud_WWriteOff.Validated
      If Not _closing Then
         If sender Is ud_PWriteOff Then
            bind_InvPlastic.EndEdit()
         Else : bind_InvWood.EndEdit()
         End If
         UpdateSums(ColumnsToSum.WriteOff)
         sp_InfoLab.Text = "Wood: " & bind_InvWood.CurRow.RowState.ToString() & " - Plastic: " & bind_InvPlastic.CurRow.RowState.ToString()
      End If
   End Sub

   Private Sub ud_PWriteOff_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ud_PWriteOff.ValueChanged, ud_WWriteOff.ValueChanged
      Dim ud As NumericUpDown = TryCast(sender, NumericUpDown)
      If ud.isValid() Then
         Console.WriteLine(ud.Name & ": " & ud.Value & " - Table: " & CType(ud.DataBindings(0).DataSource, FlufBindSource).CurRow.As(Of ReconcileDataSet.tbl_InvoicesRow).WriteOff)
      End If
   End Sub

If you change the NumericUpDown with the arrow keys, the Console prints the change immediately. WHen you exit the control, the OnValidated is called, enforcing the EndEdit(), and listing the current rowstate for the item, which in this situation will be "Modified".

Now, Clear out the changes and try again. This Time, instead of using the Arrow keys to change the value of the UpDown control, simply type in a number and press the "Enter", and then TAB to exit out of the control focus. In this circumstance, upon hitting enter the ValueChanged() event fires, printing the changed value, and when you exit the control the Validated() event first and the similar path as when using the Arrow keys occurs here as well.

The Third time we try this, change the value by typing in a number, but then directly tab out to the next control. The ValueChanged() event triggers, but the OnValidated() event does not.

Any ideas why? (I figure most likely I'll put in an OnLeave() event that does something or other, or perhaps I'll move the BindSource.EndEdit() into the ValueChanged() event, not sure how much that will effect, but I am still very curious as to why the Enter key has such an effect upon the update process of the numeric updown. Perhaps all the controls act the same way, *shrug*, it is just an interesting design if it is intentional)

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
"Never Trust a computer. Your brain is smarter than any micro-chip."
JaedenRuiner  Monday, July 27, 2009 2:12 PM
Actually, I've found I should update this, because if you have the console.writeline()'s in place, in either the valuechanged or the onleave event, and they access the bind source's current row value, it updates every time whether or not you hit the <enter> key before exiting the control. but if you dont' have the writeline's, and thus do not access the bind source's current value, it does not update when you type the value and exit. very strange...

J"SD"a'RR

"Never Trust a computer. Your brain is smarter than any micro-chip."
JaedenRuiner  Monday, July 27, 2009 2:38 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView errorIcon - how to change
• Datagridview & Crystal Report
• Browsable attribute breaking change?
• Override DataRow.GetChildRows for late-bind fetch
• Accessing Selected Data On Active Window.
• DataGridView checkbox invisible problem
• DataGridView order of selected rows is not the same as order of data
• what is vb.net code for update the values and save the changed values in datagrid using vb.net windows application
• Limits on the number of tables or fields in a datasource?
• Dataview error