我有一门课,ExpenseItem
还有一个基于该课的列表。
我目前正在设计一个具有组合框的表单,该组合框允许我选择特定类型的ExpenseItem
旅行,并在列表框中显示所有结果。
表单代码(tripSelect
是组合框,listExpenses
是列表框):
private void LoadExpenseList()
{
tripSelect.Items.Clear();
var dateSorted =
from e in roster
group e by e.Trip into tripGroup
select new { Trip = tripGroup.Key };
foreach (var e in dateSorted)
tripSelect.Items.Add(e.Trip);
}
private void LoadExpenseDetail()
{
listExpenses.Items.Clear();
var dateSorted =
from e in roster
orderby e.Trip
select e;
foreach (var e in dateSorted) ;
}
private void ExpenseRecorderForm_Load(object sender, EventArgs e)
{
}
private void tripSelect_SelectedIndexChanged(object sender, EventArgs e)
{
selectedExpense = (ExpenseItem)roster.ToFind((string)tripSelect.SelectedItem);
listExpenses.Items.Add(selectedExpense);
}
private void listExpenses_SelectedIndexChanged(object sender, EventArgs e)
{
tripTextBox.Text = selectedExpense.Trip;
tripTextBox.Enabled = false;
descriptionTextBox.Text = selectedExpense.Description;
amountTextBox.Text = selectedExpense.Amount.ToString();
paymentMethodTextBox.Text = selectedExpense.PaymentMethod;
dateExpenseTimePicker.Value = selectedExpense.Date;
dateExpenseTimePicker.Enabled = true;
noteTextBox.Text = selectedExpense.Note;
}