我有一个WPF Datagrid
,其中一列是DataGridComboBoxColumn
。
我需要根据此Combobox中的所选项目更改某些列值。
以下是xaml
代码:
<DataGrid Name="dgInvDetails" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<mui:DataGridTextColumn Header="ID" Binding="{Binding ID}" IsReadOnly="True"/>
<mui:DataGridComboBoxColumn Header="Item Description" x:Name="DdlItems" IsReadOnly="True" SelectedItemBinding="{Binding Description}"
SelectedValuePath="ItemID"
DisplayMemberPath="Description">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<EventSetter Event="SelectionChanged" Handler="ItemSelectionChanged" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</mui:DataGridComboBoxColumn>
<mui:DataGridTextColumn x:Name="TextQuantity" Header="Quatity" Binding="{Binding Quatity}" IsReadOnly="True" />
<mui:DataGridTextColumn x:Name="TextUnitPrice" Header="Unit Price" Binding="{Binding UnitPrice}" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
因此,当用户更改项目Combobox的选择时,我需要在TextUnitPrice
中设置一些特定值。
我在服务器端创建了以下方法:
private void ItemSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = sender as ComboBox;
InvoiceDetails selectedItem = this.dgInvDetails.CurrentItem as InvoiceDetails;
// Getting the invoice detail from DB
// Setting the invoice detail unit price to TextUnitPrice
}
那么如何访问其他文本框并为其中的所选行设置值?