121

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?

4 Answers 4

259

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

HeadersVisibility="Column"
3
  • 3
    gridView.HeadersVisibility = DataGridHeadersVisibility.Column; Dec 2, 2014 at 7:46
  • 3
    If someone wants to remove all headers: HeadersVisibility="None" Nov 11, 2015 at 14:17
  • This seems much more correct than setting the width to 0.
    – Alejandro
    Aug 22, 2020 at 18:24
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
  • 1
    for some reason, I couldn't find that anywhere. Feel a bit "doh!" now, but thank you.
    – Tim Almond
    May 19, 2010 at 13:45
  • 35
    user556009's answer is the correct answer for this. I.e. set HeadersVisibility="Column"
    – Sameera
    Jan 26, 2012 at 5:45
  • 7
    @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. Oct 2, 2012 at 16:01
  • 1
    @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.
    – Alex34758
    Feb 16, 2018 at 6:33
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
  • Try this. It is helpful Jan 9, 2020 at 8:37
  • That the answer this question deserve
    – Orace
    Jun 11, 2020 at 14:38
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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.