Link to home
Start Free TrialLog in
Avatar of ladarling
ladarlingFlag for United States of America

asked on

ListBox Control's Intrinsic Conversion from Double to Object Problem

Ok crowd, here is the issue. Idle_Mind and I have been dealing with another authors problem, and we have come across an interesting issue with the ListBox control. If you use the Add() method of the list box control on a Double, the lisbox's conversion from Double to Object widens the Double as expected, but unexpectedly returns junk data. To see this for yourself, add a listbox to a forn and try:

 For LoopCount As Double = 1 To 2 Step 0.1
            ListBox1.Items.Add(LoopCount)
Next

NOTE: I'm not looking for a workaround, there are any number of ways around it. This is just an academic discussion about the object itself and what the problem is or may be. If you think you know, there are points in it for you.
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ladarling

ASKER

It seems that every floating point type *except* decimal behaves this way, even 'Object' when inferred to be floating point (which is probably inferred to be a 'Single' in this context, though I am not sure). Very very odd.
For those wondering why I am bothering with this, take a read to what Idle showed me yesterday:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.objectcollection.add.aspx
The screenshot below shows the different types I played with....

sshot.png
What I meant to say:
 (which is probably inferred to be a 'Double' in this context, though I am not sure)
It is apparently treated as a double judging from the output, but I am willing to believe anything at this point :-)