2017-06-05 98 views
0

我想在文本框或列表框中显示我的值。我有一个学生课,主要形式,另一种形式来添加学生。我成功地将学生添加到字典中,并且键是学生ID,还有其他值(名,姓等)。现在我想要将名字检索到列表框或文本框。我怎样才能做到这一点? 我添加了一个屏幕显示,使其略显清晰。 enter image description here在文本框或列表框中显示值c#

+0

你在哪里存放呢? – Krishna

+0

字典对象在主窗体和其他窗体中均创建。但是从其他形式使用函数将值传递给主窗体。我不确定这是否正确。 – Buddhi

+0

应用程序关闭后,你不需要这些数据? – Krishna

回答

0

试试这个

创建一个学生类

public class Student 
{ 
     public string StudentID { get; set; } 
     public string StudentName { get; set; } 
     //remaining properties 
} 

创建回购

public static class StudentRepository 
{ 
    private static List<Student> students = new List<Student>(); 
    public static void AddOrUpdateStudent(Student s) 
    { 
      var stu = students.Where(m=>m.StudentID = s.StudentID).FirstOrDefault(); 
      if(stu == null) 
      { 
       students.Add(s); 
      } 
      else 
      { 
       students.remove(stu); 
       students.Add(s); 
      } 

    } 
} 

形式使用该如下

StudentRepository.AddOrUpdateStudent(s);