Reader Level:
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#.
  • 0
  • 0
  • 14126



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;
 
        }
    }
}

COMMENT USING

Trending up