2017-03-05 2 views
0

ここに私のコードがあります。私はちょうど私の領収書のための新しいクラスを作成しました。 このコードは[追加]ボタン用です。Cのバインディングをリセットする#

else if (!string.IsNullOrEmpty(cmbProductName.Text) && !string.IsNullOrEmpty(txtQuantity.Text)) 
     { 
      Receipt obj = new Receipt() { Id = order++, ProductName = Convert.ToString(cmbProductName.SelectedItem), Quantity = Convert.ToInt32(txtQuantity.Text), Price = Convert.ToDouble(txtPrice.Text) }; 
      total += obj.Price * obj.Quantity; 
      receiptBindingSource.Add(obj); 
      receiptBindingSource.MoveLast(); 
      Clear();   
     } 
     txtTotal.Text = String.Format("P{0}", Convert.ToString(total)); 

    } 

これは新しいデータの場合です。しかし、私が新しいをクリックすると、私は私のreceiptBindingSourceのデータをリフレッシュまたはリセットできません。合計金額は依然として計算を続ける。

 private void New() { 
     cmbProductName.Text = string.Empty; 
     txtPrice.Text = string.Empty; 
     txtQuantity.Text = string.Empty; 
     txtCustomerName.Text = string.Empty; 
     txtCustomerNumber.Text = string.Empty; 
     txtTotal.Text = string.Empty; 
     txtCash.Text = string.Empty; 
     receiptBindingSource.Clear(); 
    } 

誰もが、私は新しいデータを追加カントので、私のreceiptBindingSourceをリフレッシュ、リセットする方法を私を助けることができます。新しいものを追加できるように、デバッグをやめる必要があります。私を助けてください。

答えて

1

問題は、この行である:あなたはどこにでもtotalの値をリセットしていない

total += obj.Price * obj.Quantity; 

+0

どのようなコードを使用しますか?私を助けてくれますか? –

+0

リセットのために作成したメソッドでは、totalの値を0に設定します。 – Sparrow

+0

どうもありがとう!それは私のために働く:Dありがとう、ありがとう、ありがとう! –

関連する問題