This is getting annoying really <_<
I hope I'm wrong and this is just an issue with my code, cause I've already run into two bugs in C# today. I'm calling the "ValueChanged" event on a numericUpDown control, except whenever I press the up or down arrows on the control, the value passed from the event is the value the control was. For example if the control is 10, and I press the up arrow, it becomes 11, but the value passed back from "valueChanged" when I get the current value is 10.
Normally I'd just add 1, but when typing directly into the control and pressing enter, the valueChanged event returns the correct figure. So it would seem that someone took a shortcut while developing C#. When pressing the up arrow on a numericUpDown control the "valueChanged" event triggers on the button press, rather then when the acctual event occurs.
I'm a tad annoyed as I've been working on this for the past few hours with no luck. I've tried other events as well, the validation event works, but occurs a tad after the button is pressed, and the lag time just isn't very nice in a GUI.
I'm hoping I'm just missing something simple. If anyone has any idea whats going on or a solution it would be much appreciated :)
M FPosted Apr 6, 2008, 11:07 AM
haha thanks, it works now : ) seems it was my fault. I'd like to understand this though...
This was my original code:
lstBooks.FindItemWithText(SelectedISBN()).SubItems[2].Text = nmudCopies.Text;
now I changed it to this, basically just using .Value instead of .Text
lstBooks.FindItemWithText(SelectedISBN()).SubItems[2].Text = nmudCopies.Value.ToString();
I've only really started using C# recently (was using C++ and mainly creating programs using openGL), so form stuff is a tad new to me, and I was simply using .Text to get the value out of most controls. So I'm just wondering what the difference here is between .value and .text, obviously somethings going on behind the scenes...
Scott LyslePosted Apr 6, 2008, 10:52 AM
There was something similar with date time picker control events in 2005; are you using 2005 or 2008? I checked it in 2008 and it the value changed event returns the new rather than the old value and it worked correctly when incrementing or decrementing the value. I also checked the date time picker in 2008 and it returns the new rather than the old value on its value changed event as well. It seems to me that I used the validation event (as you mentioned) to get the new value from the control in 2005; maybe someone else has a better solution.
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { MessageBox.Show(numericUpDown1.Value.ToString(), "Value Changed"); }