标题:代码没问题,一运行就报错。
取消只看楼主
yebanbaobei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2012-12-24
结帖率:66.67%
已结贴  问题点数:20 回复次数:3 
代码没问题,一运行就报错。
//主窗口
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Studengt studengt;
        private void button1_Click(object sender, EventArgs e)
        {
            studengt = new Studengt();
            studengt.Usename = textBox1.Text;
            studengt.Yuwen = Convert.ToInt32(textBox2.Text);
            studengt.Shuxue = Convert.ToInt32(textBox3.Text);
            int zongfen =Convert.ToInt32(textBox1.Text) +Convert.ToInt32(textBox2.Text);
            int pingjunfen =( Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text))/2;
            Comm.list.Add(studengt);
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            for (int i = 0; i < Comm.list.Count; i++)
            {
                ListViewItem list1 = new ListViewItem(Comm.list[i].Usename, i);
                list1.SubItems.Add(Comm.list[i].Yuwen.ToString());
                list1.SubItems.Add(Comm.list[i].Shuxue.ToString());
                list1.SubItems.Add(Comm.list[zongfen].ToString());
                listView1.Items.Add(list1);
               
            }
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}

//Studengt类
namespace 项目1
{
    class Studengt
    {
        private string usename;

        public string Usename
        {
            get { return usename; }
            set { usename = value; }
        }
        private int yuwen;

        public int Yuwen
        {
            get { return yuwen; }
            set { yuwen = value; }
        }
        private int shuxue;

        public int Shuxue
        {
            get { return shuxue; }
            set { shuxue = value; }
        }
    }
}

//公用类Comm
namespace 项目1
{
    class Comm
    {
        public static List<Studengt> list = new List<Studengt>();
    }
}

[ 本帖最后由 yebanbaobei 于 2013-4-15 14:39 编辑 ]
搜索更多相关主题的帖子: private public 
2013-04-15 14:35
yebanbaobei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2012-12-24
得分:0 
回复 2楼 shangsharon
list1.SubItems.Add(Comm.list[i].(这里是没有zongfen调用)ToString());
2013-04-15 14:47
yebanbaobei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2012-12-24
得分:0 
回复 4楼 yhlvht

版主请问下,除开第一次按提交是出现1个,后面在录入数据按提交,
就会出现重复的?要是再按多一次提交就会出现3条重读的数据.
2013-04-15 15:24
yebanbaobei
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2012-12-24
得分:0 
回复 6楼 yhlvht
我就是总觉得少了什么。。。谢谢版主。
2013-04-15 15:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-404284-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.100217 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved