Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to deduct total amount when deleted on the datagridview

$
0
0
So I have a school program which is the ordering system.
I have 3 buttons namely add order, delete order, update order.

I need some help on the subtraction part
in which the selected rows and the cell where column name **Amount** belong will be deducted from the `txtTotalAmount`

[![Here's the picture for reference if not understood][1]][1]

I already did the addition part like when add order button clicked total Amount textbox sum it
Here's the code:

    int totalx = 0;  
    int Totalxr = int.Parse(txtTotal.Text);
    totalx += Totalxr;
    txtTotalAmount.Text = totalx.ToString();

I tried the subtraction part but I failed to do it.
Here's my code

    int Totalxr = int.Parse(txtTotal.Text);
    int txrs = int.Parse(txtTotalAmount.Text);
    int str = txrs - Totalxr;
    txtTotalAmount.Text = str.ToString();

 


clarification of what I want to achieved.

Example the total would be 7300.

if selected row has an amount of 4300 which is shown in the image above  then totalamount textbox should update when it is deleted and making the total amount of 3000. then again if user again selects the row with 3000 under the column amount the totalamount will be updated from 3000 to 0 since the selected row amount has 3000 and the current total is 3000.

Hope I already clarify what I wanted to do.

Lastly Why I can't remove the `txtAmount.text `which I will be doing after add order is successful
like when I used `txtAmount.Clear();` the text is still there. while the other txts which I use the clear function works.

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>