Search code examples
c#wpfxamldatagrid

What is the (Empty) Column at Beginning of WPF Datagrid called


In my example of a datagrid, as first column a small empty column is shown:

Image.

But only after I added items to the ItemsSource:

dgListings.ItemsSource = null;
dgListings.ItemsSource = listingViewModel.LoadedListings;

This column is created, it seems to be a specific elemet, if I click the header of it, all rows are selected:

Image

This is my XAML code:

<DataGrid x:Name="dgListings" ItemsSource="{Binding LoadedListings}" CanUserAddRows="False" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="ID"         Width="*"   IsReadOnly="True" Binding="{Binding listing_id}"/>
        <DataGridTextColumn Header="Quantity"   Width=".5*" IsReadOnly="True" Binding="{Binding quantity}"/>
        <DataGridTextColumn Header="Title"      Width="2*"  IsReadOnly="True" Binding="{Binding title}"/>
        <DataGridTextColumn Header="Price"      Width="*"   IsReadOnly="True" Binding="{Binding price}"/>
        <DataGridTextColumn Header="Currency"   Width="*"   IsReadOnly="True" Binding="{Binding currency_code}"/>
    </DataGrid.Columns>
</DataGrid>

How can I remove it and what is it called?


Solution

  • They are called row headers and you can remove them by setting HeadersVisibility to Column, because by default this property is set to All, which includes row and column headers.

    <DataGrid x:Name="dgListings" HeadersVisibility="Column" ItemsSource="{Binding LoadedListings}" CanUserAddRows="False" AutoGenerateColumns="False">