private void Form1_Load(object sender, EventArgs e) { List <Customer> customerList = CustomerDB.GetCustomers(); List <Invoice> invoiceList = InvoiceDB.GetInvoices(); var invoices = from invoice in invoiceList join customer in customerList on invoice.CustomerID equals customer.CustomerID orderby customer.Name, invoice.InvoiceTotal descending select new { customer.Name, invoice.InvoiceID, invoice.InvoiceDate, invoice.InvoiceTotal }; string customerName = ""; int i = 0; foreach (var invoice in invoices) { if (invoice.Name != customerName) { lvInvoices.Items.Add(invoice.Name); customerName = invoice.Name; } else { lvInvoices.Items.Add(""); } lvInvoices.Items[i].SubItems.Add(invoice.InvoiceID.ToString()); lvInvoices.Items[i].SubItems.Add( Convert.ToDateTime(invoice.InvoiceDate).ToShortDateString()); lvInvoices.Items[i].SubItems.Add(invoice.InvoiceTotal.ToString("c")); i += 1; } }
private void Form1_Load(object sender, EventArgs e) { List <Invoice> invoices = InvoiceDB.GetInvoices(); List <Customer> customers = CustomerDB.GetCustomers(); var Invoices = from i in invoices join c in customers on i.CustomerID equals c.CustomerID orderby c.Name, i.InvoiceTotal descending select new { c.Name, i.InvoiceID, i.InvoiceDate, i.InvoiceTotal }; foreach (var inv in Invoices) { ListViewItem item = new ListViewItem(inv.Name); item.SubItems.Add(inv.InvoiceID.ToString()); item.SubItems.Add( Convert.ToDateTime(inv.InvoiceDate).ToShortDateString()); item.SubItems.Add(inv.InvoiceTotal.ToString("c")); lvInvoices.Items.Add(item); } }