0

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:

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

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

here is my ProductQuantity definition:

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");
        }
    }
Community
  • 1
  • 1
JihadiOS
  • 381
  • 2
  • 13

1 Answers1

0

There you see the reason, if you notice the ProductQuantity definition it's value(in the getter) depends on ProductCartoons, if this value is 0 you always get 0 for ProductQuantity.

I would suggest use debugger and go through step by and see what is causing 0 in this case.

Hari Prasad
  • 16,716
  • 4
  • 21
  • 35
  • if `ProductCartoons` is `0` there is no `ProductQuantity` at all means `0` the same for `ProductItems` i know but they are not 0s – JihadiOS Jun 01 '16 at 09:29
  • Do you mean to say `ProductCartoons` is not _zero_? – Hari Prasad Jun 01 '16 at 09:31
  • yes `ProductCartoons` is not `0` thats indeed with code – JihadiOS Jun 01 '16 at 09:32
  • Can you try modifying this condition `ProductCartoons >= 0` to `ProductCartoons > 0` – Hari Prasad Jun 01 '16 at 09:33
  • okay now i see after i looked up little to my xaml code i am using new instance of that class in this process not the exact instance for the binding so in this case am not updating `ProductCartoons` or `ProductItems` that means they are `0` for the new instance i created thanks lot man. your last comment works fine if you edit your answer and include it i can mark it as answer @Hari Prasad – JihadiOS Jun 01 '16 at 09:37