【C++】数据访问界面(课上练习)
2019-06-03 10:56
141 查看
[code]时间呐 等等我~ 美好的事物陪伴我们 且显然他们不曾远去~
目录:
数据绑定
- Windows窗体应用程序
- 相应位置添加代码
- 运行结果
>> Program.cs
[code]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
[code]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
[code]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~
相关文章推荐
- C++文本查询程序 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++文本查询程序 定义类管理数据 用智能指针 C++Primer练习12.30
- C++文本查询程序 定义类管理数据 用引用共享数据 不用智能指针 C++Primer练习12.27
- 3第一周课后练习·阅读计划(3)-使用函数来访问私有数据成员
- php 数据访问练习:投票页面
- C++文本查询程序 不要定义类和智能指针管理数据 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++文本查询程序 定义类管理数据 用引用共享数据 不用智能指针 C++Primer练习12.27
- C++文本查询程序 定义类管理数据 用智能指针 C++Primer练习12.30
- 【c#界面和后台c++通信】跨平台数据通信的选择:Google ProtoBuf
- C++文本查询程序 定义类管理数据 用智能指针 用StrBlob代替vector<string> C++Primer 练习12.32
- C++文本查询程序 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++文本查询程序 定义类管理数据 用智能指针 C++Primer练习12.30
- C++文本查询程序 定义类管理数据 用引用共享数据 不用智能指针 C++Primer练习12.27
- C/C++ 操控访问SQLite3 数据库
- 数据访问......简单练习
- 如何在C/C++中动态分配二维数组并访问其中的数据
- C++文本查询程序 不要定义类和智能指针管理数据 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果
- C++文本查询程序 定义类管理数据 用引用共享数据 不用智能指针 C++Primer练习12.27
- C++文本查询程序 定义类管理数据 用智能指针 C++Primer练习12.30
- C++文本查询程序 定义类管理数据 用智能指针 用StrBlob代替vector<string> C++Primer 练习12.32