在我的 WPF 应用程序中,我有一个绑定到 ObservableCollection 的 DataGrid。
<DataGrid x:Name="DataGridTeilnehmer" HorizontalAlignment="Left" VerticalAlignment="Top" CellEditEnding="DataGridTeilnehmer_CellEditEnding" AutoGenerateColumns="False" SelectionMode="Single">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Teilnehmer" CellEditingTemplate="{StaticResource TeilnehmerEditTemplate}" CellTemplate="{StaticResource TeilnehmerCellTemplate}" />
<DataGridComboBoxColumn Header="Pass" />
...
DataGridComboBoxColumn 应为每一行填充单独的值。这些值取决于第一列的条目。所以,我想在 CellEditEnding 事件中设置数据,如下所示:
private void DataGridTeilnehmer_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (!commiting)
{
commiting = true;
DataGridTeilnehmer.CommitEdit(DataGridEditingUnit.Row, false);
commiting = false;
// check, whether it is the first column that has been edited
if (...)
// get the list<string> for the combobox depending on the edited content
// get the combobox of the current row and bind the calculated list<string> to it
}
}
}
我怎样才能做到这一点?
编辑:我想要实现的一个例子。
我有客户名单,每个客户都有单独的票。在第一列中选择了客户后,我想加载该客户拥有的票证列表并将其加载到下一列 - 组合框列。
提前致谢,
弗兰克