I need to get the values of two LINQ queries in to one listbox. Currently I have it going in to two separate listboxe's side by side so it works but is not optimal. The data is essentially a list of names and a list of values that goes with those names.
var getTotalsColumn = from p in dataTable select p.TOTALS;
foreach (var totals in getTotalsColumn)
{
employeeByIspListBox.Items.Add(totals);
}
var getNamesColumn = from p in dataTable select p.NAME;
foreach (var names in getNamesColumn)
{
listBox1.Items.Add(names);
}
How can I combine this to put for example John Doe : 21
into one listbox.
Both Totals and Name returns type String.
It sounds like you just want:
var items = dataTable.Select(p => string.Format("{0} : {1}", p.NAME, p.TOTALS));
listBox1.Items.AddRange(items.ToArray());
See more on this question at Stackoverflow