是否有可能在从datagrid中删除一行后,它链接到一个命令或事件,所以我也可以将它从SQL中删除?
现在我有这个网格。我可以通过i:Interaction.Triggers编辑它。
删除有类似内容吗?
XAML:
<DataGrid ItemsSource="{Binding Contactpersons}" AutoGenerateColumns="False" Grid.Column="1" Margin="35,99,8,10" Grid.Row="5" Grid.ColumnSpan="3">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding EditCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Header="Naam" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Bedrijf" Binding="{Binding Company}" />
<DataGridTextColumn Header="Functie" Binding="{Binding JobRole/Name}"/>
<DataGridTextColumn Header="Stad" Binding="{Binding City}" />
<DataGridTextColumn Header="E-mail" Binding="{Binding Email}" />
<DataGridTextColumn Header="Telefoon" Binding="{Binding Phone}" />
<DataGridTextColumn Header="GSM" Binding="{Binding Cellphone}" />
</DataGrid.Columns>
</DataGrid>
C#:
public ICommand EditCommand
{
get { return new RelayCommand<SelectionChangedEventArgs>(Edit); }
}
private void Edit(SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count > 0)
{
Contactperson b = e.RemovedItems[0] as Contactperson;
Contactperson.EditPerson(b);
}
}
对于删除而不是编辑,是否存在类似这样的内容?
答案 0 :(得分:0)
在datagrid中,你有一个名为UnloadingRow
的事件 private void dgv_UnloadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
// Add your deletion code from SQL.
}
更新: -
请查看此链接here