I have a numericupdown control on my WinForm that I'd like to use to send text to an Excel range on the valuechanged event. However, this control does not appear to function how I assumed it would. When I click the up or down arrow, the value in the numericupdown box needs to be sent to my Excel range, however, it seems to be delayed by one click. For example, if the control currently has 5 as it's value, and I press the up arrow, the value then changes to 6, but my Excel range says 5. Then if I click the up arrow again, the numericupdown box value is 7, but my Excel range says 6. It seems the event is delayed by a click. I'm assuming what's happening is the value is being sent to Excel before the value in the numericupdown control has actually changed. Any suggestions on what I'm doing wrong?

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
    StatVar.xlApp.Sheets("New Calculator Input").Range("J5").Value = NumericUpDown1.Text
End Sub
有帮助吗?

解决方案

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
StatVar.xlApp.Sheets("New Calculator Input").Range("J5").Value = NumericUpDown1.Value
End Sub
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top