【发布时间】:2020-02-27 15:58:33
【问题描述】:
我正在建立一个学生列表,但不知道如何解决问题。我正在使用组合框来显示所有已创建的学生。我使用以下代码将学生直接保存到组合框中:
private void btnSpeichern_Click(object sender, EventArgs e)
{
Student StudentSave = new Student
{
ID = txtStudentID.Text,
FirstName = txtFirstName.Text,
LastName = txtLastName.Text,
Age = nudAge.Value,
Height = nudHeight.Value,
Schoolclass = txtSchoolClass.Text,
Gender = cbxGender.Text,
};
cbxStudentIDs.Items.Add(StudentSave);
}
cbxStudentIDs 代表组合框。我想将学生 ID 作为显示的名称,但它为我保存的每个学生显示“WindowsFormsApp2.Form1+Student”。
我正在使用 Visual Studio 2019 C#。感谢您提供任何有用的建议!
【问题讨论】:
-
这能回答你的问题吗? C# ComboBox with Text and Value