126

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?

5 Answers 5

266

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

HeadersVisibility="Column"
Sign up to request clarification or add additional context in comments.

3 Comments

gridView.HeadersVisibility = DataGridHeadersVisibility.Column;
If someone wants to remove all headers: HeadersVisibility="None"
This seems much more correct than setting the width to 0.
162

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.

4 Comments

for some reason, I couldn't find that anywhere. Feel a bit "doh!" now, but thank you.
user556009's answer is the correct answer for this. I.e. set HeadersVisibility="Column"
@scorpion: setting only HeadersVisibility="Column" will cause some column headers to be shifted horizontally compared to cell contents. Setting both HeadersVisibility="Column" and RowHeaderWidth="0" (or just the last one) fixes this problem.
@JarekKardas It was my case. I played with various HeadersVisibility and RowHeaderWidth values and can't get rid of the shift. Then I leave only HeadersVisibility="Column" and just cleaned and rebuilt the solution and the shift has gone. After that just HeadersVisibility="Column" was enough.
6

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>

2 Comments

Try this. It is helpful
That the answer this question deserve
0

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

Comments

0

We can fix by make it clean for definition :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.