How can I highlight an entire DataGrid row when a single cell is clicked?

18,267

Have you tried <DataGrid SelectionMode="Single" SelectionUnit="FullRow"> ?

But actually its the default behavior if i click a cell the entire row is highlighted

SelectionMode doc: https://msdn.microsoft.com/en-us/library/system.windows.controls.datagridselectionmode%28v=vs.110%29.aspx

SelectionUnit doc: https://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectionunit%28v=vs.110%29.aspx

Share:
18,267
DaveDev
Author by

DaveDev

Updated on June 15, 2022

Comments

  • DaveDev
    DaveDev almost 2 years

    I have a DataGrid defined as follows. When I click a cell in the DataGrid only the cell is highlighted. How can I change it so that when I click the cell the entire row is highlighted?

    <DataGrid Name="fileGrid" AutoGenerateColumns="False" Height="150" Width="Auto" 
                Margin="10,10,0,0" 
                HorizontalAlignment="Left" VerticalAlignment="Top" SelectionChanged="fileGrid_SelectionChanged">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Company Name" 
                x:Name="columnCompanyName" 
                Binding="{Binding Path=Customer.CompanyName}"
                IsReadOnly="True">                    
            </DataGridTextColumn>
    
            <DataGridTextColumn Header="Customer Surname" 
                x:Name="columnCustomerSurname" 
                Binding="{Binding Path=Customer.Surname}"
                IsReadOnly="True">
            </DataGridTextColumn>
    
            <DataGridTextColumn Header="Customer Address" 
                x:Name="columnAddressLine1" 
                Binding="{Binding Path=Customer.Address.Line1}"
                IsReadOnly="True">
            </DataGridTextColumn>
    
            <DataGridTextColumn Header="Customer City" 
                x:Name="columnCity" 
                Binding="{Binding Path=Customer.Address.City}"
                IsReadOnly="True">
            </DataGridTextColumn>
    
        </DataGrid.Columns>
    </DataGrid>
    
  • DaveDev
    DaveDev about 12 years
    Thank you - this is exactly it. I have to wait 4 minutes to select this as the correct answer.