在文本框或列表框中显示值c#

时间:2017-06-05 01:46:06

标签: c# class dictionary textbox listbox

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

1 个答案:

答案 0 :(得分:0)

试试这个

创建学生班

------------------------
LATEST FOREIGN KEY ERROR
------------------------
170604 21:52:27 Error in foreign key constraint of table kffg_simulations/bid:

    FOREIGN KEY (`simulation_id` , `item_round_status_round` , `clock_item_id`)
    REFERENCES `kffg_simulations`.`item_round_status` (`simulation_id` , `round` , `clock_item_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bid_bidder1`
    FOREIGN KEY (`bidder_idx` , `simulation_id`)
    REFERENCES `kffg_simulations`.`bidder` (`idx` , `simulation_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bid_bid_type1`
    FOREIGN KEY (`bid_type_id`)
    REFERENCES `kffg_simulations`.`bid_type` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bid_pea_category1`
    FOREIGN KEY (`switch_to_pea_category_id`)
    REFERENCES `kffg_simulations`.`pea_category` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_bid_bid_status1`
    FOREIGN KEY (`bid_status_id`)
    REFERENCES `kffg_simulations`.`bid_status` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB:
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
for correct foreign key definition.

创建回购

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);
             }

     }
}