我有一个文本框,其值是自然正数,因为我做了一些计算后,从另一个文本框中生成它,我的文本框保存的结果肯定是数字,当我尝试将该值转换为它始终给出0的整数,而文本框的值保持大于0且根本不为空。
我都尝试转换方法在这里msdn
我也试过TryParse
方法在这里成立Convert textbox text to integer
我创建2个破发点看到转换后的文字都文本框中的文本和整数值的结果
这里是我的代码:将文本框文本转换为整数给出0
MessageBox.Show(updateProductTQ.Text, "Quantity");
p.ProductQuantity = int.Parse(updateProductTQ.Text);
MessageBox.Show(p.ProductQuantity.ToString(), "Quantity");
updateProductTQ
是我的文本框的名字,p.ProductQuantity
是整数
第一MessageBox
输出是在文本框中显示的数字10现在
第二个MessageBox
输出很大0
有人能告诉我为什么我得到0吗?
我尝试另一个文本框持有数中的转换和正常工作是很奇怪的事情
这里是我的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; }
}
,并通过这些文本框提出的所有通过结合和完成它运作良好:
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");
}
}
你可以发布'updateProductTQ.Text'的值吗? –
你能告诉我们'ProductQuantity'属性是如何定义的吗? –
您测试过的产品是否为ProductCarton> 0?然后它不会直接返回存储的'_ProdQuan',而是重新计算它。 –