I'm trying to update a label when the combo box selection is changed so that it presents a count from a query. Unless I specify suing a string the where clause, it wont let me use the value from the combobox.SelectedValue, it returns a zero.
where (o.ShipCountry == "USA")
And what I've been trying:
private void cmbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var ord = (from o in db.Orders
where (o.ShipCountry == cmbCountry.SelectedValuePath)
select o.ShipCountry).Count();
lblOrders.Content = ord;
}
Here's a screen of the issue to help. The zero should be a count of all the orders to a certain country specified by the combo box.
Any help is much appreciated!
I actually realized my problem! The LINQ query I used to populate the ComboBox used an anonymous type to reference the column being selected. I named it "cc".
var cmb = (from c in db.Customers
orderby c.Country descending
select new { cc = c.Country }).Distinct();
Which meant the binding path was Binding Path=SelectedValue.cc
var cmb = (from c in db.Customers
orderby c.Country descending
select c.Country).Distinct();
By removing the anonymous type I was able to access the SelectedValue of the combobox.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.