Question How do I get the values in all columns of a row with button click event in code behind?

destro

Well-known member
Joined
Mar 28, 2020
Messages
46
Programming Experience
1-3
I have an ItemTemplate in my WPF app main window which shows the details of all personnel in SQLite database.

Each row has 8 columns and one of them is the delete button. I want to get the values inside all fields of the row whose delete button is clicked on in my code-behind.

I have successfully loaded the data but unable to figure out how to get all values in the row when I clicked the row's delete button.

I want to pass those values in database delete operation.

This is my itemTemplate code:
C#:
<ItemsControl x:Name="RecordsTable" FontSize="16" Margin="0,87,0,0">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition SharedSizeGroup="Col1" />
                                <ColumnDefinition SharedSizeGroup="Col2" />
                                <ColumnDefinition SharedSizeGroup="Col3" />
                                <ColumnDefinition SharedSizeGroup="Col4" />
                                <ColumnDefinition SharedSizeGroup="Col5" />
                                <ColumnDefinition SharedSizeGroup="Col6" />
                                <ColumnDefinition SharedSizeGroup="Col7" />
                                <ColumnDefinition SharedSizeGroup="Col8" />
                            </Grid.ColumnDefinitions>

                            <Label Background="Transparent" BorderThickness="1" x:Name="DashaButton" Grid.Column="0"  Content="{Binding Personname}"  BorderBrush="Black" />
                            <Label Grid.Column="1" HorizontalContentAlignment="Center" Content="{Binding datetime}" BorderThickness= "1" BorderBrush="Black"  />
                            <Label BorderThickness="1" HorizontalContentAlignment="Center" Grid.Column="2"  Content="{Binding DayLight}" BorderBrush="Black"/>
                            <Label BorderThickness="1" HorizontalContentAlignment="Center" Grid.Column="3"  Content="{Binding PositionCenter}" BorderBrush="Black"/>
                            <Label BorderThickness="1" HorizontalContentAlignment="Center" Grid.Column="4"  Content="{Binding City}" BorderBrush="Black"/>
                            <Label BorderThickness="1" HorizontalContentAlignment="Center" Grid.Column="5"  Content="{Binding Altitude}" BorderBrush="Black"/>
                            <Label BorderThickness="1" HorizontalContentAlignment="Center" Grid.Column="6"  Content="{Binding PhoneNumber}" BorderBrush="Black"/>
                            <Button x:Name="Delete" Background="Transparent"  Foreground="Black" Content="Delete" Click="Delete_Click" CommandParameter="{Binding Path=ID}" BorderThickness="1"  Grid.Column="7" BorderBrush="Black" />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>


This is the view of my ItemTemplate:
Screenshot (138).png

Can I get any help in this matter?

Thanks in advance.
 
Aren't you simply deleting an entire row?

Or do you need the individual values to be passed for some sort of operation?
 
Back
Top Bottom