public class newStudent_class
{
public String firstName;
public String secondName;
public DateTime birthday;
public override string ToString()
{
return firstName+ " " + secondName + ", " + birthday.ToString("dd.MMM.yyy");
}
}类创建newStudents (第一个/第二个名称和b-day),单击按钮将这些值存储在listBox中。
listBox1.Items.Add(myNewStudent);问题就在这里:我希望listBox1.选择them以名、名和by分隔,并将它们存储在lblFirstName.Text =“.”中。lblSecondName.Text =“.”B天也一样
发布于 2021-02-04 00:23:46
您可以做的是为列表框的SelectedIndexChanged添加一个事件处理程序。然后,在事件处理程序中,可以将选定的项转换为类类型,并在标签中填充这些值。
void MyListBox_SelectedIndexChanged(object sender, EventArgs e)
{
var newStudent = myListBox.SelectedItem as newStudent_class;
if (newStudent != null)
{
lblFirstName.Text = newStudent.firstName;
// etc...
}
}https://stackoverflow.com/questions/66037458
复制相似问题