C# WPF数据网格组合框selectedItem
我有一个DataGrid,其中有一个客户ID组合框,每个客户ID可能有许多帐户ID,这些帐户ID分配在他们自己的组合框中。我只想做的是,当用户从组合框中选择客户ID时,帐户ID将使用所选的特定CustomerID进行更新 我想我的代码就快到了 这里我在combobox elementstyle中应用了customerId的itemsource。如您所见,当从“客户”框中选择项目时,我的属性为SelectedItemC# WPF数据网格组合框selectedItem,c#,wpf,xaml,datagrid,observablecollection,C#,Wpf,Xaml,Datagrid,Observablecollection,我有一个DataGrid,其中有一个客户ID组合框,每个客户ID可能有许多帐户ID,这些帐户ID分配在他们自己的组合框中。我只想做的是,当用户从组合框中选择客户ID时,帐户ID将使用所选的特定CustomerID进行更新 我想我的代码就快到了 这里我在combobox elementstyle中应用了customerId的itemsource。如您所见,当从“客户”框中选择项目时,我的属性为SelectedItem <DataGridComboBoxColu
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding DataContext.EntityCollection,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Window}}"/>
<Setter Property="DisplayMemberPath" Value="Name"/>
<Setter Property="SelectedItem" Value="{Binding SelectedItem}"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
</Style>
</DataGridComboBoxColumn.ElementStyle>
因此,在帐户Id的组合框中,我不确定将SelectedItem.AID代码放在哪里
我已经将它放在第一行的SelectedValueBinding属性中,但它不起作用。是否需要将SelectedItem放在EditingElementStyle标记的Itemsource属性中
<DataGridComboBoxColumn SelectedValueBinding="{Binding SelectedItem.AID}" SelectedValuePath="SID" Header="SID" Width="70">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding DataContext.EntityCollection,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Window}}"/>
<Setter Property="DisplayMemberPath" Value="AID"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding DataContext.EntityCollection,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType=Window}}"/>
<Setter Property="DisplayMemberPath" Value="AID"/>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
</Style>
</DataGridComboBoxColumn.ElementStyle>
然而,我可能离这里很远,所以任何帮助我都将不胜感激
谢谢
为了传输对您的财产所做的更改,非常需要检查模式
现在,要对其他组合框应用任何更改,例如添加或创建项,您需要使用另一个ObservableCollection并将其绑定到第二个组合框。如果您这样做了,当对第一个组合框进行任何更改时,您可以控制第二个组合框的项目
这只是一个简短的示例:
private uint _ID;
public uint ID
{
get { return _ID; }
set
{
if (_ID == value) return;
_ID = value;
NotifyOfPropertyChange("ID");
// Do something with your second ComboBox.
// You could create another ObservableCollection and bind that to your second ComboBox and add some items representing the Account IDs
}
}
在进行更改时,不要忘记通知视图
如果这不是你想要的答案,请更具体一些。你的实际问题很难理解,我只理解了第一段并解释了如何归档你想做的事。睡觉后我同意你的看法,我想要的是更简单的,我会再写一个问题,谢谢
SelectedValueBinding="{Binding ID, Mode=TwoWay}"
private uint _ID;
public uint ID
{
get { return _ID; }
set
{
if (_ID == value) return;
_ID = value;
NotifyOfPropertyChange("ID");
// Do something with your second ComboBox.
// You could create another ObservableCollection and bind that to your second ComboBox and add some items representing the Account IDs
}
}