| Issue 5: | NumericUpDown control has a secret "Text" property | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Discussion
What is the expected output? What do you see instead?
You would expect to see a .Text property in the intellisense list for a .Net control that has a text-like display in it, such as a text box (ok) or a NumericUpDown(not ok).
So, when instructed by SBS C# 2003 to enter:-
ProductService productService = new ProductService();
try
{
AsyncCallback callback = new AsyncCallback(howMuchCallback);
IAsyncResult running =
productService.BeginHowMuchWillItCost(productName.Text,
Int32.Parse(numberRequired.Text), callback,
productService);
}
catch (Exception ex)
{
MessageBox.Show("Error sending request: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
the part where it asks for Int32.Parse(numberRequired.Text raises a number of issues.
1. when writing the code, Intellisense doesn't give you a .Text Option
2. when trying to figure out how to resolve this, there are a few options:-
//works
//IAsyncResult running = productService.BeginHowMuchWillItCost(ProductNameTxt.Text, Int32.Parse(NumberRequired.Value.ToString()), callBack, productService);
//sticking with using the Int32.Parse, but use it with the .Value property instead. This works but seems wasteful
// better
//IAsyncResult running = productService.BeginHowMuchWillItCost(ProductNameTxt.Text, (int)NumberRequired.Value, callBack, productService);
//better as saves having to convert a decimal to a string to convert to an int!
3. Using the original code as intended works, but is confusing as there is no intellisense help!
4. Using the amended code removes an invalid Input format error as it casts the decimal to an int (removing any decimal information)
Please use labels and text to provide additional information.
Dec 7, 2011
(No comment was entered for this change.)
Status:
Done
|
76.6 KB View Download