This is what i'm trying to accomplish ,the city is a combobox
因此,我有一个包含3个不同客户的datagridcombobox,客户类具有名称,名字,地址,手机和邮政编码。我有一个不同的类City,其中包含ZipCode和Name(邮政编码)。因此,我遍历了所有这些内容,以检索包含所有邮政编码名称字符串的列表。但是我无法将其放在组合框上的selecteditem上,因为它是一个数据网格,并且有3种不同的组合框。 itemsource已经在组合框上设置了,但是我不知道如何在这些组合框上输入selecteditem。
This is what i've got now,without the selecteditem
这是我的xaml代码:
<DataGrid AutoGenerateColumns="False" Name="CustomersDataGrid" HorizontalAlignment="Center" VerticalAlignment="Top"
CanUserAddRows="False" Width="auto" Height="auto" Grid.Row="1" Grid.Column="1">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" />
<DataGridTextColumn Binding="{Binding FirstName}" Header="Firstname" />
<DataGridTextColumn Binding="{Binding Address}" Header="Address" />
<DataGridComboBoxColumn DisplayMemberPath="Name" Header="City" x:Name="CityComboBoxColumn"/>
<DataGridTextColumn Binding="{Binding CellPhone}" x:Name="CellPhone" Header="Cellphone" />
</DataGrid.Columns>
</DataGrid>
这是初始化组件背后的代码:
_allCities = cityRepository.GetAll();
_allCustomers = customerRepository.GetAll();
_cities = new List<string>();
CustomersDataGrid.ItemsSource = _allCustomers;
for(int i = 0; i < _allCustomers.Count; i++)
{
for (int j = 0; j < _allCities.Count; j++)
{
if(_allCustomers[i].ZipCode == _allCities[j].ZipCode)
{
_cities.Add(_allCities[j].Name);
}
}
}
{
}
CityComboBoxColumn.ItemsSource = _allCities;