通过ListView(WPF)从数据库中删除行

时间:2022-09-26 10:56:33
<ListView Height="330" VerticalAlignment="Top"   Name="Customers" Grid.Row="1" >
    <ListView.View>
                <GridView >
                    <GridViewColumn Header="FirstName" Width="100" DisplayMemberBinding="{Binding FirstName}" />
                    <GridViewColumn Header="LastName" Width="100" DisplayMemberBinding="{Binding LastName}" />
                    <GridViewColumn Header="Email" Width="100" DisplayMemberBinding="{Binding Email}" />
                    <GridViewColumn Header="Phone" Width="100" DisplayMemberBinding="{Binding Phone}" />
                </GridView>
            </ListView.View>
</ListView>

I use a service for the Delete function. I need to send a customer in order to delete it from the table. I want to add a column for each row that deletes that row from my DB. I have no idea how to do it. Thanks for the help!

我使用删除功能的服务。我需要发送一个客户才能从表中删除它。我想为从我的数据库中删除该行的每一行添加一列。我不知道该怎么做。谢谢您的帮助!

1 个解决方案

#1


0  

Add a column containing Delete buttons for every row :

为每一行添加一个包含删除按钮的列:

<GridViewColumn>
     <GridViewColumn.CellTemplate>
         <DataTemplate>
            <Button Content="Delete" Click="DeleteButton_Click"/>
         </DataTemplate>
     </GridViewColumn.CellTemplate>
</GridViewColumn>

Code :

代码:

    private void DeleteButton_Click(object sender, RoutedEventArgs e)
    {
        Customer rowEntity = ((Button)e.OriginalSource).DataContext as Customer;
        /* Delete code ... */
    }

#1


0  

Add a column containing Delete buttons for every row :

为每一行添加一个包含删除按钮的列:

<GridViewColumn>
     <GridViewColumn.CellTemplate>
         <DataTemplate>
            <Button Content="Delete" Click="DeleteButton_Click"/>
         </DataTemplate>
     </GridViewColumn.CellTemplate>
</GridViewColumn>

Code :

代码:

    private void DeleteButton_Click(object sender, RoutedEventArgs e)
    {
        Customer rowEntity = ((Button)e.OriginalSource).DataContext as Customer;
        /* Delete code ... */
    }