WPF Datagrid unable to select full row when perform single click on cell

Chris Choo 1 Reputation point
2021-07-15T09:09:44.687+00:00

I have a normal Datagrid which bound to a observable collection.

Problem : When I perform single click on the [Price] or [Qty] cell, it will highlight the content inside the cell and let me edit but the respective row is not selected. Instead I have to perform a double click on the cell in order to edit and select the respective row at the same time (This is what I would like to achieve). I have look on the internet for few days but no one seems to have same problem like me instead they have the opposite (not very sure) scenario.

<Grid Grid.Row="1" Margin="10">  
                    <DataGrid Name="dgProduct"  
                      AutoGenerateColumns="False"  
                      MaxWidth="930"  
                      MinWidth="500"  
                      CanUserAddRows="False"  
                      SelectionUnit="FullRow"  
                      SelectionMode="Single"  
                      Padding="9"  
                      ItemsSource="{Binding Path=ProductList, Mode=TwoWay}"  
                      SelectedItem="{Binding Path=SelectedProduct, Mode=TwoWay}">  
  
                        <DataGrid.Columns>  
                            <DataGridTextColumn Header="" IsReadOnly="True" Binding="{Binding Path=Id}" />  
                            <DataGridTextColumn Header="Product No." IsReadOnly="True" Binding="{Binding Path=Product_no}" />  
                            <DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding Path=Name}" />  
                            <DataGridTextColumn Header="Barcode" IsReadOnly="True" Binding="{Binding Path=Barcode}" />  
                            <DataGridTextColumn Header="Price" Binding="{Binding Path=Price, UpdateSourceTrigger=PropertyChanged}" />  
                            <DataGridTextColumn Header="Qty(Meter)" Binding="{Binding Path=Total_stock, UpdateSourceTrigger=PropertyChanged}"/>  
                            <DataGridTextColumn Header="Subtotal" IsReadOnly="True" Binding="{Binding Path=Subtotal}" Width="*"/>  
                        </DataGrid.Columns>  
                    </DataGrid>  
                </Grid>  

The cell is in edit mode but not selected (SelectedProduct is still empty)
115041-capture-1.png

Thanks in advance.

Developer technologies | Windows Presentation Foundation
{count} votes

1 answer

Sort by: Most helpful
  1. Adam Jachocki 46 Reputation points
    2021-09-09T10:09:24.52+00:00

    If you can modify cell value, you won't be able to do full row select. So you have to disable cell editing. Then it will work.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.