Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete extra lines in WPF DataGrid? [duplicate]

Tags:

c#

wpf

xaml

Does somebody know how to delete these lines in the last non-existing column in the WPF DataGrid? And also how to remove the last extra row?

enter image description here

Here is my xaml:

<WindowChrome.WindowChrome>
    <WindowChrome CaptionHeight="30" />
</WindowChrome.WindowChrome>

<Border BorderBrush="#FF333333" BorderThickness="1">
    <DataGrid Name="ParametersConfigGrid"
              AutoGenerateColumns="False"
              Loaded="ParametersConfigGrid_OnLoaded">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Order" Binding="{Binding Order}" />
            <DataGridTextColumn Header="Parameter Name" Binding="{Binding ParameterName}" />
            <DataGridTextColumn Header="Designation" Binding="{Binding Designation}" />
        </DataGrid.Columns>
    </DataGrid>
</Border>

Thanks!

like image 877
Yevheniy Tymchishin Avatar asked Dec 02 '25 06:12

Yevheniy Tymchishin


1 Answers

To get rid of the last row, in your DataGrid set the CanUserAddRows property to False:

<DataGrid Name="ParametersConfigGrid"
          AutoGenerateColumns="False"
          Loaded="ParametersConfigGrid_OnLoaded"
          CanUserAddRows="False">

To get rid of the lines that extend past your columns, use a row style. You can just put the style into your Window Resources.

<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}">
    <Setter Property="BorderThickness" Value="0" />
</Style>

You may need to add a style for the cells if you want borders on cells. You would do it in a very similar way as for the row.

like image 141
Nik Avatar answered Dec 03 '25 19:12

Nik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!