使用列表填充文本框时。显示方法如下。
private void Display()
{
StringBuilder sb = new StringBuilder();
foreach (Player dude in _FootballRoster)
{
if (btnUSA.Checked == true)
{
sb.AppendLine("\r\nName: " + dude.getName() + " \r\n Team: " + dude.getTeam() + "\r\n Birthday: " + dude.getBirthday() + "\r\n Height(in):" + dude.getHeight() + "\r\n Weight(lbs): " + dude.getWeight() + "\r\n Salary(USD): " + dude.getSalary());
}
if (btnUSA.Checked == false)
{
sb.AppendLine("\r\nName: " + dude.getName() + " \r\n Team: " + dude.getTeam() + "\r\n Birthday: " + dude.getBirthday() + "\r\n Height(meters):" + (dude.getHeight()) / 39.3701 + "\r\n Weight(kg): " + (dude.getWeight()) / 2.20462 + "\r\n Salary(CD): " + (dude.getSalary()) / 1.31);
}
}
txtRosterLog.Text = sb.ToString();
}
当您单击 btnName 时尝试实现排序方法时,我希望“排序方式:名称”出现在文本框的顶部,但我当前的代码将它放在所有播放器的底部。
当前名称排序代码:
private void btnName_Click(object sender, EventArgs e)
{
_FootballRoster = _FootballRoster.OrderBy(dude => dude.Name).ToList();
Display();
txtRosterLog.AppendText("SORT BY: NAME ");
}
有任何想法吗?我试过使用 txtRosterLog.Text.Insert(0, "SORT BY NAME)" 但这也没有用。