【发布时间】:2013-12-27 02:44:45
【问题描述】:
晚安,
我希望我的组合框选择其中的第一项。我正在使用 C# 和 WPF。我从数据集中读取数据。填充组合框:
DataTable sitesTable = clGast.SelectAll().Tables[0];
cbGastid.ItemsSource = sitesTable.DefaultView;
组合框 XAML 代码:
<ComboBox
Name="cbGastid"
ItemsSource="{Binding}"
DisplayMemberPath="Description"
SelectedItem="{Binding Path=id}"
IsSynchronizedWithCurrentItem="True" />
如果我尝试:
cbGastid.SelectedIndex = 0;
它不起作用。
【问题讨论】:
-
你检查你的绑定属性了吗?这推翻了 SelectedIndex!
标签: c# wpf xaml combobox dataset