user4134476
user4134476

Reputation: 385

How to remove lines in extra unused space in a DataGrid

enter image description here

I created a DataGrid shown in the image above, which has extra unused space in the right part. Could you tell me how it is possible to remove lines in the unused space?

CAUTION: In my case, the extra unused space MUST exist in the right part. I'd like to remove lines alone.

SOLUTION:

I resolved my question by setting GridLinesVisibility="NONE" and setting a template for a DataGridCell as shown in the code below. Thank you very much for your help, everyone.

<Style TargetType="DataGridCell">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Border BorderBrush="Black" BorderThickness="0, 0, 0.5, 0.5"
                        Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}">
                        <ContentControl Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Upvotes: 0

Views: 477

Answers (2)

itzmebibin
itzmebibin

Reputation: 9439

You can remove extra rows by using CanUserAddRows property. Also you can remove extra created column by using AutoGenerateColumns property.

<DataGrid CanUserAddRows="False" AutoGenerateColumns="False">
.................
</DataGrid>

Upvotes: 0

Kevin Nacios
Kevin Nacios

Reputation: 2853

set GridLinesVisibility="Vertical" on the datagrid, and then override the cellstyle:

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="BorderThickness" Value="0,0,0,1"/>
    </Style>
</DataGrid.CellStyle>

which will set the border on each cell to only the bottom border, and each column will have vertical grid lines displayed only.

Upvotes: 1

Related Questions