Tim Almond
Tim Almond

Reputation: 12716

How Do I Hide wpf datagrid row selector

I'm using the WPF DataGrid control to show some details and a select button, and I don't need the gray selector column down the left-hand side. It's also ruining the beauty of my design.

Is there a way to remove it, or how can I style it to match if not?

Upvotes: 124

Views: 66668

Answers (5)

ChuongHo
ChuongHo

Reputation: 87

We can fix by make it clean for definition :

 <DataGrid.RowHeaderStyle>
 <Style TargetType="DataGridRowHeader">
     <Setter Property="Width" Value="1" />
 </Style>

</DataGrid.RowHeaderStyle>

Upvotes: 0

Maghalakshmi Saravana
Maghalakshmi Saravana

Reputation: 811

To remove the Row header(Gray field) in Datagrid in WPF

<DataGrid x:Name="TrkDataGrid" HeadersVisibility="Column">
</DataGrid>

To remove or hide the Column Header in DataGrid WPF

<DataGrid x:Name="TrkDataGrid" HeadersVisibility="Row">
</DataGrid>

To remove or hide both Column and Row Header in DataGrid WPF

<DataGrid x:Name="TrkDataGrid" HeadersVisibility="None">
</DataGrid>

Upvotes: 6

George Mavritsakis
George Mavritsakis

Reputation: 7093

Instead of setting the Width you can completely hide the row headers by setting on the DataGrid

HeadersVisibility="Column"

Upvotes: 264

Frank Kotulak
Frank Kotulak

Reputation: 17

Had the same problem.

Looks like the RowHeaderWidth is not supported in XAML BUT you can specify in the code behind right after the bind and it takes out that crappy selector column.

grdName.RowHeaderWidth = 0

Upvotes: 0

slugster
slugster

Reputation: 49985

Use the RowHeaderWidth property:

<my:DataGrid RowHeaderWidth="0" AutoGenerateColumns="False" Name="dataGrid1" />

Note that you can also specify a style or template for it also, should you decide you really do like it and want to keep it because you can do something cool with it.

Upvotes: 162

Related Questions