Reputation: 73
I have this code, but there is still no data in ComboBox
.
using (var context = new DatabaseContext())
{
var xd = (from c in context.CHall
orderby c.CinemaHallName
select c).ToList();
foreach (var c in xd)
{
cbCinemaHall.ItemsSource = c.CinemaHallName;
cbCinemaHall.DisplayMemberPath = "CinemaHallName";
}
}
Upvotes: 0
Views: 188
Reputation: 39946
You don't need foreach
for this purpose. Just set the ItemsSource
of your ComboBox
to xd
. Like this:
using (var context = new DatabaseContext())
{
var xd = (from c in context.CHall
orderby c.CinemaHallName
select c).ToList();
cbCinemaHall.ItemsSource = xd;
cbCinemaHall.DisplayMemberPath = "CinemaHallName";
}
Upvotes: 1