Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have three text boxes in a form and two check box associated to textbox1 and textbox2.
Another textbox is named as grandtotal. When I checked on check box it insert value in two text boxes. Now I want to insert sum of value into third text box which is named as grandtotal

Below are the my codes for the text box 1 and text box 1


C#
private void checkBoxAdmission_CheckedChanged(object sender, EventArgs e)
        {
            SQLHelper objsql = new SQLHelper();
            objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID  = 1";

            objsql.AddParameter("FeetypeID", checkBoxAdmission.Checked);
            DataTable dt = objsql.getDataTable(false);
            if (dt.Rows.Count > 0)

                txtAdmissionFee.Text =dt.Rows[0]["SettingValue"].ToString();

            objsql.Close();
            objsql.Dispose();
        }

        private void checkBoxMonthly_CheckedChanged(object sender, EventArgs e)
        {
            SQLHelper objsql = new SQLHelper();
            objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID  = 2";
            
            objsql.AddParameter("FeetypeID", checkBoxMonthly.Checked);
            DataTable dt = objsql.getDataTable(false);
            if (dt.Rows.Count > 0)

                txtMonthlyFee.Text = dt.Rows[0]["SettingValue"].ToString();

            objsql.Close();
            objsql.Dispose();
        }


C#
private void txtGrandTotal_TextChanged(object sender, EventArgs e)
Posted
Updated 22-Sep-12 6:44am
v2
Comments
[no name] 22-Sep-12 12:46pm    
And? How exactly is this a problem?
Manir55 22-Sep-12 12:51pm    
when i make a check on check box 1 it gives a value to textbox1 similarly when i make a check on checkbox2 it gives a value in textbox2 now I want to add both value to third text box automatically. I want to know how to do it? Please help
[no name] 22-Sep-12 14:37pm    
I am still not seeing what your problem could possibly be. Create a changed event on the checkbox, get the 2 values you want to add together, add them together and put the sum in the other textbox.

1 solution

You can fill the third textbox with the second checkbox click itself like below...
C#
private void checkBoxMonthly_CheckedChanged(object sender, EventArgs e)
        {
            // Declare grandTotal. Take datatype as per your requirement.
            int grandTotal;
 
            SQLHelper objsql = new SQLHelper();
            objsql.SqlText = " select SettingID,SettingValue from tblSettings where SettingID  = 2";
            
            objsql.AddParameter("FeetypeID", checkBoxMonthly.Checked);
            DataTable dt = objsql.getDataTable(false);
            if (dt.Rows.Count > 0)
 
                txtMonthlyFee.Text = dt.Rows[0]["SettingValue"].ToString();
 
            objsql.Close();
            objsql.Dispose();
            
            // Add values and fill to third textbox.
            grandTotal = Convert.ToInt32(txtAdmissionFee.Text) + Convert.ToInt32(txtMonthlyFee.Text);
            txtGrandTotal.Text = grandTotal.ToString(); 
        }

NOTE: Take datatype and conversion mechanism as per your requirements.

Thanks...
 
Share this answer
 
Comments
Thanks for accepting...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900