Remove the blank column in a WPF DataGrid

后端 未结 2 1971
忘掉有多难
忘掉有多难 2021-02-07 05:31

I use a DataSet to populate a DataGrid in WPF (C#). The result is:

\"enter

I want

相关标签:
2条回答
  • 2021-02-07 06:11

    Avoid setting static Height and Width.

    Use ColumnWidth="*" to share the space between your DataGridColumns

    <DataGrid x:Name="dg1" ColumnWidth="*"
              HorizontalAlignment="Left" VerticalAlignment="Top" Margin="25,10,0,0"
              EnableRowVirtualization="false" EnableColumnVirtualization="false" 
              FontFamily="2  badr" FontSize="20" FlowDirection="RightToLeft" 
              CanUserAddRows="False" CanUserReorderColumns="False" />
    
    0 讨论(0)
  • 2021-02-07 06:17

    You can set the last column or one column of your Grid with

    <DataGridTextColumn Header="Surname"
                        Width="*"
                        Binding="{Binding Path=Surname,Mode=TwoWay}" IsReadOnly="True">
      <DataGridTextColumn.ElementStyle>
        <Style TargetType="TextBlock">
          <Setter Property="HorizontalAlignment" Value="Left" />
          <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
      </DataGridTextColumn.ElementStyle>
    </DataGridTextColumn>
    
    0 讨论(0)
提交回复
热议问题