question

ChrisChoo-6459 avatar image
0 Votes"
ChrisChoo-6459 asked ajachocki answered

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

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.

windows-wpf
capture-1.png (13.8 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is it a normal DataGrid of WPF or something else UWP/WinUI? WPF doesn't give you this style in DataGrid normally. In WPF it's the opposite, you've to click the cell twice to get into edit mode and the row will be selected normally.

1 Vote 1 ·

Thanks for your help! I just found out that it is caused by the theme

 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
                 <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />

Though I would like to use this theme, any idea on how to achieve what I described above?

0 Votes 0 ·

No idea about MaterialDesign.

0 Votes 0 ·

I have the same issue using MaterialDesign Library. Have you solved the problem?

0 Votes 0 ·

1 Answer

ajachocki avatar image
0 Votes"
ajachocki answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.