作者:淡漠初夏0_176 | 来源:互联网 | 2023-05-18 22:23
ihaveatextboxanditsvalueisnaturalpositivenumberbecauseamgeneratingitfromanothertex
i have a text box and its value is natural positive number because am generating it from another text boxes after doing some calculation and my text box hold the result which is definitely number, when i try to convert the value to integer it always gives 0 while the text box hold a value greater than 0 and not null at all.
i tried both converting methods in here msdn
also i tried the TryParse
method founded here Convert textbox text to integer
i create 2 break points to see the result of both text box text and integer value after converting the text
here is my code:
我有一个文本框,它的值是自然正数,因为我做了一些计算后从另一个文本框生成它,我的文本框保存结果肯定是数字,当我尝试将值转换为整数时,它总是给0文本框保存大于0的值,而不是null。我尝试了两种转换方法在这里msdn也尝试了这里建立的TryParse方法将文本框文本转换为整数我创建2个断点,以查看转换文本后文本框文本和整数值的结果这里是我的代码:
MessageBox.Show(updateProductTQ.Text, "Quantity");
p.ProductQuantity = int.Parse(updateProductTQ.Text);
MessageBox.Show(p.ProductQuantity.ToString(), "Quantity");
updateProductTQ
is my text box name, p.ProductQuantity
is integer
the first MessageBox
output is the number shown in the text box 200
now
the second MessageBox
output is big 0
updateProductTQ是我的文本框名,p.ProductQuantity是整数,第一个MessageBox输出是文本框200中显示的数字,现在第二个MessageBox输出大0
can someone tell me why i get 0 ???
i try the conversion for another text box holding number and it works fine that is really weird thing
谁能告诉我为什么我得到0 ???我尝试转换另一个文本框保持号码,它工作正常,这是非常奇怪的事情
here is my ProductQuantity
definition:
这是我的ProductQuantity定义:
public int ProductQuantity
{
get
{
if (ProductCartoons >= 0)
{
if (ProductBigBox > 0 && ProductSmallBox > 0 && ProductMedBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductBigBox * ProductMedBox * ProductSmallBox * ProductItems;
}
else
if (ProductBigBox > 0 && ProductMedBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductBigBox * ProductMedBox * ProductItems;
}
else
if (ProductBigBox>0 && ProductSmallBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductBigBox * ProductSmallBox * ProductItems;
}
else
if (ProductMedBox > 0 && ProductSmallBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductMedBox * ProductSmallBox * ProductItems;
}
else
if (ProductBigBox>0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductBigBox * ProductItems;
}
else
if (ProductMedBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductMedBox * ProductItems;
}
else
if (ProductSmallBox > 0 && ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductSmallBox * ProductItems;
}
else
if (ProductItems >= 0)
{
_ProdQuan = ProductCartoons * ProductItems;
}
}
return _ProdQuan;
}
set { _ProdQuan = value; }
}
and it Raised by these text boxes all done by binding and it is working well:
这些文本框都是通过绑定完成的,它运行良好:
public int ProductCartoons
{
get { return _Cartoons; }
set
{
_CartoOns= value;
RaisePropertyChangedEvent("ProductQuantity");
}
}
public int ProductBigBox
{
get { return _BigBox; }
set
{
_BigBox = value;
RaisePropertyChangedEvent("ProductQuantity");
}
}
public int ProductMedBox
{
get { return _MedBox; }
set
{
_MedBox = value;
RaisePropertyChangedEvent("ProductQuantity");
}
}
public int ProductSmallBox
{
get { return _SmallBox; }
set
{
_SmallBox = value;
RaisePropertyChangedEvent("ProductQuantity");
}
}
public int ProductItems
{
get { return _Items; }
set
{
_Items = value;
RaisePropertyChangedEvent("ProductQuantity");
}
}
1 个解决方案