Click here to Skip to main content
15,562,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,


I'm using datagrid in code and fires selection changed event of datagrid and as well delete button in datagrid having click event.

My problem is when i click on button it fires selection changed event of grid and on next click delete event of button.That means for delete button click i have to press mouse clicks two times.

Here is my Code:

XML
<sdk:DataGrid FontSize="10" IsReadOnly="True" AutoGenerateColumns="False" Grid.ColumnSpan="2" Margin="1,3,0,8" Name="lstMotionAreaDetails" ScrollViewer.HorizontalScrollBarVisibility="Auto" SelectionMode="Single" TabIndex="30" ToolTipService.ToolTip="Stored Motion Information" SelectionChanged="lstMotionAreaDetails_SelectionChanged">
                            <sdk:DataGrid.Columns>
                                <sdk:DataGridTextColumn Binding="{Binding Sr, Mode=TwoWay}" Header="#" Width="30" />
                                <sdk:DataGridTextColumn Binding="{Binding regionName, Mode=TwoWay}" Header="Name" Width="110" />
                                <sdk:DataGridTextColumn Binding="{Binding sensitivity, Mode=TwoWay}" Header="Sensitivity" Width="75" />
                                <sdk:DataGridTemplateColumn Header="Action" Width="55">
                                    <sdk:DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Button Height="26" Name="btnDeleteArea" Width="26" CommandParameter="{Binding SelectedItem, ElementName=dataGrid}" Click="btnDeleteArea_Click">
                                                    <Image Name="imgDelete" Height="25" Source="/LocalStoreConfiguration;component/Camera_Configuraion/images/delete.png" Width="25" />
                                                </Button>
                                            </Grid>
                                        </DataTemplate>
                                    </sdk:DataGridTemplateColumn.CellEditingTemplate>
                                </sdk:DataGridTemplateColumn>
                            </sdk:DataGrid.Columns>
                        </sdk:DataGrid>
Posted

1 solution

Don't use SelectionChanged event of gridview. Use only button click event and store primary key of record in Tag property of button you will get desired record.
 
Share this answer
 
Comments
KIDYA 30-Jun-12 6:51am    
But I need selection changed event as I do operation on row selection changed when i select that row..is there any alternative to selection changed?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900