c# - 属性数据未输出到控件
问题描述
在我当前的一个项目中,我一直在尝试开发一个系统,该系统将从一个表单上的文本框输入数据,并将它们输入到另一个表单上的列表中,以便它们可以通过另一个表单上的列表框和标签显示为手动输入数据库的数据参考。
//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;
}
在我的一生中,从我的立场来看,这个程序似乎应该有效。我的 Intellisense 没有给我语法错误,我试图亲自与其他业余程序员一起审查我的逻辑,但无论出于何种原因,数据不会输出到第二种形式的控件。我唯一能想到的是,我以某种方式通过引用变量作为参数传递给我的RetrieveStudentInfo
方法,而这些变量实际上并没有以某种方式传递,但这不应该是正确的。任何关于这种情况的建议将不胜感激。
解决方案
推荐阅读
- javascript - 如何连接 d3.js 和 solr json 响应?
- php - DialogFlow V2 API - Webhook 响应为空
- python - 我可以制作一个列表理解,在 for 循环之后附加一个值吗
- mongodb - 即使在创建正确的索引后,MongoDB 也会扫描大量文档
- javascript - 有没有办法简化这个两行表达式?(解构和重组)
- elasticsearch - 使用路由对别名进行 Elasticseach 过滤搜索
- javascript - Firebase Firestore:如何通过使用 async/await 从快照中获取 ref
- ruby-on-rails - 检查关联记录的空值
- angular - 使用自定义 tslint 规则导致找不到实现
- sql - 为什么在数据库查询中求和给出 NULL