我写一个程序,有必要在其中切换当前状态,有必要在计划事件时计划它,它被认为是一个对象,该对象具有自己的字段,例如事件的开始时间和结束时间,我希望在生成工作表装箱时输出此对象。 告诉我该怎么做?
List<ChangeStatus> events = new List<ChangeStatus>();
private void toPlanButton_Click(object sender, EventArgs e)
{
string comboBoxTypeNumber = comboBoxType.SelectedItem.ToString();
DateTime Time = new DateTime();
Time = dateTimePicker1.Value;
DateTime longTime = new DateTime();
longTime = dateTimePicker2.Value;
ChangeStatus statusEvent = new ChangeStatus();
statusEvent.StartEvent = Time;
statusEvent.LongEvent = longTime;
statusEvent.TypeEvent = comboBoxTypeNumber;
events.Add(statusEvent);
TimeComparer tc = new TimeComparer();
events.Sort(tc);
}
如何在列表框中显示对象? 必须显示对象列表,因为将来我要编辑对象
listBoxEvent.Items.Add("type: " + statusEvent.TypeEvent + ";" + " start: " + statusEvent.StartEvent + ";" + " long: " + statusEvent.LongEvent + " min;"); - work
答案 0 :(得分:0)
您可以使用System.Linq
Linq来获取字符串文本,并可以在AddRange()
集合上调用Items
方法,例如
List<string> listData = events.Select(x => "type: " + x.TypeEvent + ";" + " start: " + x.StartEvent + ";" + " long: " + x.LongEvent + " min;").ToList();
listBoxEvent.DataSource = listData;