ARTICLE

Total in TextBox of two TextBoxes in C#

Posted by Vilas Gite Articles | C# Language April 10, 2011
How to use Total in TextBox in two TextBoxes in C#.
Reader Level:



TextBox.gif

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication10
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection();
        DataTable dt;
        DataRow dr;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'tRAILDataSet.CAL_TABLE' table. You can move, or remove it, as needed.
            this.cAL_TABLETableAdapter.Fill(this.tRAILDataSet.CAL_TABLE);
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            btnSave.Enabled = false;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = true;
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";

            btnAdd.Enabled = false;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(textBox1.Text);
            int k = Convert.ToInt32(textBox2.Text);
            int uItem1Tot = a + k;
            textBox3.Text = uItem1Tot.ToString();

            dt = tRAILDataSet.Tables["CAL_TABLE"];
          
            dr = dt.NewRow();
 
            dr[0] = textBox1.Text;
            dr[1] = textBox2.Text;
            dr[2] = textBox3.Text;

            dt.Rows.Add(dr);

            cAL_TABLETableAdapter.Update(tRAILDataSet.CAL_TABLE);

            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;

            btnAdd.Enabled = true;
            btnSave.Enabled = false;
 
        }
    }
}

Login to add your contents and source code to this article
post comment
     

Nice job thanks

Posted by surender bhyan Apr 11, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts