【C++】数据访问界面(课上练习)

时间呐 等等我~
美好的事物陪伴我们 且显然他们不曾远去~

目录:

数据绑定

  • Windows窗体应用程序
  • 相应位置添加代码
  • 运行结果

>> Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _16040226219
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());
        }
    }
}

>>Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _16040226219
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
  
        private void button1_Click(object sender, EventArgs e)
        { 
            textBox2.Text = textBox1.Text;//这是需要加的代码段
            Form2 fm = new Form2();
            fm.Show();
            this.Hide();
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";//需要加的代码段
            textBox2.Text = "";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            while (listBox1.SelectedItems.Count > 0) //需要加的代码段
            {
                listBox2.Items.Add(listBox1.SelectedItems[0]);
                listBox1.Items.Remove(listBox1.SelectedItems[0]);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox2.Items.AddRange(listBox1.Items);//需要加的代码段
            listBox1.Items.Clear();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            while(listBox2.SelectedItems.Count > 0) //需要加的代码段
            {
                listBox1.Items.Add(listBox2.SelectedItems[0]);
                listBox2.Items.Remove(listBox2.SelectedItems[0]);
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            listBox1.Items.AddRange(listBox2.Items);//需要加的代码段
            listBox2.Items.Clear();
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

>>Form2.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _16040226219
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataRow row = dataTable1.NewRow();
            row[0] = textBox1.Text.ToString();
            row[1] = textBox2.Text.ToString();
            row[2] = textBox3.Text.ToString();
            row[3] = textBox4.Text.ToString();
            dataTable1.Rows.Add(row);
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = dataTable1.Rows[0]["学号"].ToString();
            textBox2.Text = dataTable1.Rows[0]["姓名"].ToString();
            textBox3.Text = dataTable1.Rows[0]["性别"].ToString();
            textBox4.Text = dataTable1.Rows[0]["年龄"].ToString();
            dataTable1.Rows.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form1 fm = new Form1();
            fm.Show();
            this.Hide();
        }
    }
}

 

 

 

 

 

 

 

~bye~ 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值