组合框选择更改时更新标签
Updating a Label when Combobox Selection changes
我正在尝试在更改组合框选择时更新标签,以便它显示来自查询的计数。除非我在 where 子句中指定使用字符串,否则它不会让我使用 combobox.SelectedValue 中的值,它 returns 为零。
where (o.ShipCountry == "USA")
以及我一直在尝试的:
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;
}
这里有一个问题的屏幕可以提供帮助。零应该是组合框指定的某个国家/地区的所有订单的计数。
非常感谢任何帮助!
我终于意识到我的问题了!
我用来填充 ComboBox 的 LINQ 查询使用匿名类型来引用所选择的列。我把它命名为"cc".
var cmb = (from c in db.Customers
orderby c.Country descending
select new { cc = c.Country }).Distinct();
这意味着绑定路径是 Binding Path=SelectedValue.cc
var cmb = (from c in db.Customers
orderby c.Country descending
select c.Country).Distinct();
通过删除匿名类型,我能够访问组合框的 SelectedValue。
我正在尝试在更改组合框选择时更新标签,以便它显示来自查询的计数。除非我在 where 子句中指定使用字符串,否则它不会让我使用 combobox.SelectedValue 中的值,它 returns 为零。
where (o.ShipCountry == "USA")
以及我一直在尝试的:
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;
}
这里有一个问题的屏幕可以提供帮助。零应该是组合框指定的某个国家/地区的所有订单的计数。
非常感谢任何帮助!
我终于意识到我的问题了! 我用来填充 ComboBox 的 LINQ 查询使用匿名类型来引用所选择的列。我把它命名为"cc".
var cmb = (from c in db.Customers
orderby c.Country descending
select new { cc = c.Country }).Distinct();
这意味着绑定路径是 Binding Path=SelectedValue.cc
var cmb = (from c in db.Customers
orderby c.Country descending
select c.Country).Distinct();
通过删除匿名类型,我能够访问组合框的 SelectedValue。