当前位置:编程学习 > C#/ASP.NET >>

帮我看看哪里错了,急求 。高分

请大家先不要看代码,
先看我的问题
问题:当我添加成功后,第一次显示的时候,没问题。可是第二次添加完成后,listview中只保留初始值和最近添加的记录,前面添加的记录没了。这是为什么????


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 学生信息
{
  public  class Student
    {
        public string id;
        public string name;
    }
}

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

namespace 学生信息
{
    public partial class Frmadd : Form
    {
        public Frmadd()//添加信息窗体
        {
            InitializeComponent();
        }
        public Form1 f1;
        public Frmxian fx; 
        private void button1_Click(object sender, EventArgs e)//确定
        {
            fx = new Frmxian();
            fx.fd = this;
            fx.x1 = textBox1.Text;
            fx.x2 = textBox2.Text;
            fx.Chuan(fx.x1,fx.x2);
            this.Close();
            fx.MdiParent = f1;
            fx.Show();
        }
    }
}



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

namespace 学生信息
{
    public partial class Frmxian : Form
    {
        public Frmxian()//显示信息窗体
        {
            InitializeComponent();
        }
        Dictionary<string ,Student> Stu=new Dictionary<string,Student>();
        public string x1;//学号
        public string x2;//名字
        public Frmadd fd;
        public int zuo;
        private void Frmxian_Load(object sender, EventArgs e)
        {
            Student st1 = new Student();
            st1.id = "001";
            st1.name = "xcx";
            Student st2 = new Student();
            st2.id = "002";
            st2.name = "hgy";
            Student st3 = new Student();
            st3.id = "003";
            st3.name = "esfg";
            Stu.Add(st1.id,st1);
            Stu.Add(st2.id, st2);
            Stu.Add(st3.id, st3);
            Xian();
        }
      public void Xian()
        {
            foreach (KeyValuePair<string, Student> kv in Stu)
            {
                ListViewItem lv = new ListViewItem(kv.Key);
                string a = kv.Value.name;
                string[] de = {a};
                lv.SubItems.AddRange(de);
                listView1.Items.Add(lv);
            }
        }
        public void Chuan(string xuehao,string xingming)
        {
            Student st = new Student();
            st.id = xuehao;
            st.name = xingming;
            Stu.Add(st.id,st);
        }
      
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 学生信息
{
    public partial class Form1 : Form
    {
        public Form1()//主窗体
        {
            InitializeComponent();
        }
        public Frmxian fx;
        private void 查看学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            fx.MdiParent = this;
            fx.Show();

        }

        private void 新增学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Frmadd ff = new Frmadd();
            ff.MdiParent = this;
            ff.f1 = this;
            ff.Show();
        }
    }
}




















--------------------编程问答--------------------
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,