[2.0] Formatting Enabled?
Alright, let's cut to the chase. In Windows Applications, there is a Formatting Enabled field for the combobox. This would make this line of code work:
Code:
double calculation = Math.Round((Convert.ToSingle(cmbOutsideDiameter.Text) - (.01299 * Convert.ToSingle(txtPercentOfThread.Text) / Convert.ToSingle(txtThreadsPerInch.Text))), 3);
HOWEVER, I am now duplicating this program in a hand-held device and the compact framework doesn't have the Formatting Enabled field. The error I am getting because I cannot turn the Formatting Enabled thing on is, Format Exception is unhandled.
http://server2.uploadit.org/files/Fr...tException.JPG
Re: [2.0] Formatting Enabled?
So are you saying that trying to convert the Text property of cmbOutsideDiameter to a Single fails?
The FormattingEnabled property of the ComboBox class indicates whether formatting is applied to the DisplayMember. For that to have any relevance to you it would have to mean that your ComboBox is bound to a data source. If that's the case then you don't need to convert anything to a Single because your data source must contain Single objects already.
Re: [2.0] Formatting Enabled?
Yup.. I should have looked at it more before posting. One thing went wrong, and as usual, before trying to even think about it, I just posted and wasted the whole day waiting for replys. I just looked at it now and realized I forgot to incorporate 2 methods in a seperate event handler to change the values of the combobox. I am so used to everything working so swimmingly that when one thing goes wrong, I instanly go and post about it isntead of thinking about it. I gotta break this habit X_X
Re: [2.0] Formatting Enabled?
Well, while I still have a topic open, is it possible to combine these 2 lines into one?
Code:
double calculation = Math.Round((Convert.ToSingle(cmbOutsideDiameter.Text) - (.01299 * Convert.ToSingle(txtPercentOfThread.Text) / Convert.ToSingle(txtThreadsPerInch.Text))), 3);
txtHoleSize.Text = calculation.ToString("#.0000");
Re: [2.0] Formatting Enabled?
The result of Math.Round is the Double value that you want to turn into a string, so just tack the ToString onto Math.Round, i.e.:
Code:
txtHoleSize.Text = Math.Round(...).ToString(...);
Re: [2.0] Formatting Enabled?
Yea it isn't working. I would of tried that. No intellisense is coming up or anything
Re: [2.0] Formatting Enabled?
I'm not quite sure why Intellisense doesn't kick in there but it is possible to write code without Intellisense. I just tried it by typing '.ToString("#.000")' myself and it worked exactly as expected. C# is case-sensitive so, of course, you have to use the correct character casing.
Also, it is preferable to use standard format strings rather than custom. If you want a value with four decimal places then you should use "n4" or "f4" as your format string. You'll generally find that "n4" will use thousand separators while "f4" will not.
Finally, you may have a reason but it seems odd to me that you're rounding the number to three decimal places and then showing it with four. That gives an inaccurate representation of the actual value.
Re: [2.0] Formatting Enabled?
This program is for my dad, and it is EXACTLY how he wants it. I don't know his reasoning, but he just wants it that way. Lemme check typing it in without intellisense.
Wow.. Sunuva ***** VS didn't show intelisense. GRAR! What else isn't it showing me? *darting eyes*
Re: [2.0] Formatting Enabled?
VS doesn't show intellisense prompts on expressions.
Re: [2.0] Formatting Enabled?
Quote:
Originally Posted by penagate
VS doesn't show intellisense prompts on expressions.
The Intellisense in C# is better than in VB in several situations but this is one case where it's not because VB would list the members of the Double type in that situation while C# won't.
Re: [2.0] Formatting Enabled?
Yeah, I don't use VB so I couldn't compare. But, as far as my experience goes, VC# won't display the prompt on expressions, which leads me to suspect the type binding might be done at compile-time.
Re: [2.0] Formatting Enabled?
Quote:
Originally Posted by penagate
Yeah, I don't use VB so I couldn't compare. But, as far as my experience goes, VC# won't display the prompt on expressions, which leads me to suspect the type binding might be done at compile-time.
You are almost certainly correct about that because VB does perform background compilation (or whatever it's proper name is) which is how VB can flag compilation errors without requiring a build. The VB code IS compiled so Intellisense knows the type of the expression.