Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 属性数据未输出到控件_C#_List_Methods_Controls_Output - Fatal编程技术网

C# 属性数据未输出到控件

C# 属性数据未输出到控件,c#,list,methods,controls,output,C#,List,Methods,Controls,Output,在我当前的一个项目中,我一直在尝试开发一个系统,该系统将从一个表单上的文本框中获取数据输入,并将它们输入到另一个表单上的列表中,以便它们可以通过另一个表单上的列表框和标签显示,作为手动输入数据库的数据参考 //Create Attendance Report Instance AttendanceReport report = new AttendanceReport(); private void inputButton_Click(object sender, EventArgs

在我当前的一个项目中,我一直在尝试开发一个系统,该系统将从一个表单上的文本框中获取数据输入,并将它们输入到另一个表单上的列表中,以便它们可以通过另一个表单上的列表框和标签显示,作为手动输入数据库的数据参考

//Create Attendance Report Instance
    AttendanceReport report = new AttendanceReport();

private void inputButton_Click(object sender, EventArgs e)
    {
        try
        {                
            //Declare Variables
            string administratorVerify = verificationBox.Text;

            //Inputs Change Based on NewStudent Check
            if (passwordInput.Text == passwordTextBox.Text)
            {
                //Save Changes
                Save();
            }
         Relevant Section =>  else if (newStudentCheck.Checked == true)
            {
                //New Verification Instance
                VerificationClass verify = new VerificationClass();

                //Verification Gateway
                if (verify.Verify(administratorVerify) == true)
                {
                    //Send Student to Attendance Report List
                    report.DisplayStudent();
                }
                else
                {
                    MessageBox.Show("Unauthorized Password\nOnly Authorized Administrators May Access this Function");
                }
            }

            //Clear Inputs
            clearInputs();
        }
我设计了程序的一部分,用于检索数据并将其显示为第二个表单的通用实例的函数,调用第一个表单的实例来检索数据。我最初让程序在单击输入按钮时创建第二个表单的新实例,然后将实例化移出该块,使其成为通用实例

List<NewStudent> studentList = new List<NewStudent>();

private void RetrieveStudentInfo(NewStudent student)
    {
        //Temp Variables
        int ID;
        int Grade;

        //Create MainForm Instance
        MainForm reference = new MainForm();

        //Get Values
        student.Class = reference.classBox.Text;
        student.Name = reference.nameBox.Text;
        if (int.TryParse(reference.idBox.Text, out ID))
        {
            student.ID = ID;
        }
        else
        {
            MessageBox.Show("Invalid ID");
        }
        student.Password = reference.createPasswordBox.Text;
        student.District = reference.districtBox.Text;
        student.Country = reference.countryBox.Text;
        if (int.TryParse(reference.gradeBox.Text, out Grade))
        {
            student.Grade = Grade;
        }
        else
        {
            MessageBox.Show("Invalid Grade");
        }
    }

    public void DisplayStudent()
    {
        //Create Object
        NewStudent student = new NewStudent();

        //Get Student Info
        RetrieveStudentInfo(student);

        //Add Object to List
        studentList.Add(student);

        //Add Entry to Selection

        newStudentSelection.Items.Add(student.ID);
    }
private void newStudentSelection_SelectedIndexChanged(object sender, EventArgs e)
    {
        //Get Selected Item
        int index = newStudentSelection.SelectedIndex;

        //Display Data
        classOutput.Text = studentList[index].Class;
        nameOutput.Text = studentList[index].Name;
        idOutput.Text = studentList[index].ID.ToString();
        passwordOutput.Text = studentList[index].Password;
        districtOutput.Text = studentList[index].District;
        gradeOutput.Text = studentList[index].Grade.ToString();
        countryOutput.Text = studentList[index].Country;
    }
List studentList=newlist();
私人无效检索学生信息(新学生)
{
//温度变量
int-ID;
国际等级;
//创建MainForm实例
MainForm引用=新的MainForm();
//获取价值
student.Class=reference.classBox.Text;
student.Name=reference.nameBox.Text;
if(int.TryParse(reference.idBox.Text,out ID))
{
student.ID=ID;
}
其他的
{
MessageBox.Show(“无效ID”);
}
student.Password=reference.createPasswordBox.Text;
student.District=reference.districtBox.Text;
student.Country=reference.countryBox.Text;
if(int.TryParse(reference.gradeBox.Text,out Grade))
{
学生。年级=年级;
}
其他的
{
MessageBox.Show(“无效等级”);
}
}
公共图书馆(学生)
{
//创建对象
NewStudent student=新的NewStudent();
//获取学生信息
检索学生信息(学生);
//将对象添加到列表中
学生列表。添加(学生);
//将条目添加到所选内容
newStudentSelection.Items.Add(student.ID);
}
私有void newStudentSelection\u SelectedIndexChanged(对象发送方,事件参数e)
{
//获取所选项目
int index=newStudentSelection.SelectedIndex;
//显示数据
classOutput.Text=studentList[index].Class;
nameOutput.Text=studentList[index].Name;
idOutput.Text=studentList[index].ID.ToString();
passwordOutput.Text=studentList[index]。密码;
districtOutput.Text=studentList[index]。学区;
gradeOutput.Text=studentList[index].Grade.ToString();
countryOutput.Text=studentList[index].Country;
}
在我的一生中,从我的立场来看,这个计划似乎应该奏效。我Intellisense没有给我任何styntax错误,我曾试图亲自与其他业余程序员一起检查我的逻辑,但无论如何,数据都不会输出到第二种形式的控件。我唯一能想到的是,通过引用变量,我将其作为参数传递给我的
RetrieveStudentInfo
方法,但实际上并没有以某种方式传递,但这不应该是正确的。
如果您对这种情况有任何建议,我们将不胜感激。

VerificationClass,MainForm,NewsStudent。这些都是表格吗?如果是这样的话,您可以创建它们,但决不显示它们。您可能希望在屏幕上传递表单的现有引用。MainForm是第一个表单,AttendanceReport是第二个表单。Verification类只是我用来验证密码的一个类,NewStudent是我分配并试图传递给AttendanceReport控件的属性值的来源。但是您正在创建一个“新”主窗体。这个不是屏幕上的那个。