NumericUpDown control not displaying a 2byte value

Jul 14, 2025 at 12:12am
Hi,

I am trying to read and load a value from a NUmericUpDown control.

For some reason it only works up to a value of 0xFF. I need it to load a 2 byte value of 0xFFFF.

Edit... I get this error

"value was eiher too large or too small for an unsigned byte"


Any Ideas?
Last edited on Jul 14, 2025 at 1:03am
Jul 14, 2025 at 1:05am
There's a lot of missing details here. Do you have a minimal example that reproduces the issue?

The .NET NumericUpDown control's Value is a System.Decimal, which is a floating-point type that can express numbers well beyond 1-byte's worth.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.numericupdown.value
https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-decimal

Use a debugger and look at all the internal properties of the NumericUpDown control object.

The NumericUpDown control also has a Maximum property, which might set to 0xFF for you, for some reason...
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.numericupdown.maximum?view=windowsdesktop-9.0

try debugging to see what the value of Maximum is, and try to change it to, say, 0xFFFF.
Jul 14, 2025 at 1:17am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


			// NumericUpDow1
			this->NumericUpDow1->Name = L"label1fda";
			this->NumericUpDow1->Location = System::Drawing::Point(20, 475);
			this->NumericUpDow1->Text = "Enter An Object Value in Decimal";
			this->NumericUpDow1->Size = System::Drawing::Size(190, 25);
			this->NumericUpDow1->ValueChanged += gcnew System::EventHandler(this, &Main_Level_Form::NumericUpDow1_Val_Changed);
			this->NumericUpDow1->Click += gcnew System::EventHandler(this, &Main_Level_Form::NumericUpDow1_Click);
			this->NumericUpDow1->Minimum = 0;
			//this->NumericUpDow1->Maximum = 255;
			this->NumericUpDow1->Maximum = 0xFFFF;
			this->NumericUpDow1->Hexadecimal = true;


int Exit1_Jungle_Hijinxs;

private: System::Void listBox4_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
	if (listBox4->SelectedIndex == 1) {NumericUpDow1->Value = Exit1_Jungle_Hijinxs;}
}

private: System::Void NumericUpDow1_Val_Changed(System::Object^ sender, System::EventArgs^ e)
{
	
	if (listBox4->SelectedIndex == 1) {Exit1_Jungle_Hijinxs = NumericUpDow1->Value.ToInt32(NumericUpDow1->Value);}
}
Jul 14, 2025 at 5:38am
Does this help? Nothing I try works.

1
2
3
4
5
6
7
8
9
10
11
12
13
************** Exception Text **************
System.OverflowException: Value was either too large or too small for an unsigned byte.
   at System.Decimal.ToByte(Decimal value)
   at DKCEditor.Main_Level_Form.NumericUpDow1_Val_Changed(Object sender, EventArgs e) in C:\Users\Chris\source\repos\DKC_Editor10\Main_Level_Form.h:line 6582
   at System.Windows.Forms.NumericUpDown.OnValueChanged(EventArgs e)
   at System.Windows.Forms.NumericUpDown.set_Value(Decimal value)
   at DKCEditor.Main_Level_Form.listBox4_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\Chris\source\repos\DKC_Editor10\Main_Level_Form.h:line 6640
   at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.ListBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ListBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Jul 14, 2025 at 4:17pm
Well, your stacktrace is suggesting that "DKCEditor.Main_Level_Form.NumericUpDow1_Val_Changed" is directly calling Decimal.ToByte within its body. Are you sure you're running the current version of your source code? Were you ever, at one point, calling ToByte instead of ToInt32 in that callback?

Use a debugger and put a breakpoint within the body of NumericUpDow1_Val_Changed to confirm that it's even being hit.

Is the excerpt you have shown above from the Main_Level_Form class?
I should have said you should make a minimal, compileable example.

At this point my guess is that your source code is somehow out-of-date with the behind-the-scenes auto-generated forms code.
Try a clean & re-build?
Also try using findstr or grep recursively in your project directory to search for all instances of "ToByte" and manually clean up or delete any instances you find.
Last edited on Jul 14, 2025 at 5:48pm
Jul 14, 2025 at 8:06pm
Thanks for pointing me in the right direction. I used the find and replace tool and replaced a few ToByte values and now it works with no errors.

Thanks again. :)


This place is much more friendly then StackOverflow. ;)
Last edited on Jul 14, 2025 at 8:07pm
Jul 14, 2025 at 9:48pm
glad to help!
Registered users can post here. Sign in or register to post.