开发者

WPF Data Grid - How to hide the next column/row that is visible?

I'm using a WPF data grid to bind to an object (i.e. not a database). I have the horizontal alignment on Stretch. I currently have it within a Border, which is within a Grid.

However when I run the application the DataGrid has a blank column and grid showing. That is say I have 5 columns & 5 rows, then there is a blank 6th column and row showing. See image:

WPF Data Grid - How to hide the next column/row that is visible?

Question - How can I get rid of these blank rows? Note that the contents of the DataGrid are populated programmatically (i.e. are not static).

thanks

EDIT: I got the extra row fixed (via CanUserAddRows), but I still have an issue with the extra column on the right.

The issue with the extra column on the right seems to be to do with automatically setting column widths. The DataGrid is actually setup (see XAML below) such that there is a GridSplitter just on it's right. When I move the GridSplitter I note that the DataGrid columns don't resize automatically. So overall the issue is both (a) on startup there is a partial extra column visible, and (b) after moving the GridSplitter they don't resize either.

Any ideas on how to get this working?

        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition  Height="Auto"/>
                    <RowDefinition  Height="Auto"/>
                    <RowDefinition  Height="*"/>
                </Grid.RowDefinitions>
                <Label Content="Summary" Grid.Row="0" HorizontalAlignment="Center" />
                <Grid Grid.Row="1">
                    &开发者_运维技巧lt;Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <RadioButton IsChecked="{Binding Path=Period, Converter={StaticResource enumBooleanConverter}, ConverterParameter=AllTime}" Grid.Column="0">All Time</RadioButton>
                    <RadioButton IsChecked="{Binding Path=Period, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Month}" Grid.Column="1">Month</RadioButton>
                    <RadioButton IsChecked="{Binding Path=Period, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Week}" Grid.Column="2">Week</RadioButton>
                    <RadioButton IsChecked="{Binding Path=Period, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Day}" Grid.Column="3">Day</RadioButton>
                </Grid>
                <Border Grid.Row="2">
                    <DataGrid Name="SummaryDataGrid"  HorizontalGridLinesBrush="#FF726868" VerticalGridLinesBrush="#FF726868" AlternatingRowBackground="#FFD0F896" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserAddRows="False" CanUserSortColumns="True" CanUserResizeColumns="False" ColumnWidth="Auto" />
                </Border>

            </Grid>


            <GridSplitter HorizontalAlignment="Right" 
            VerticalAlignment="Stretch" Grid.Column="1" ResizeBehavior="PreviousAndNext"
            Width="5" Background="#FFBCBCBC"/>

            <Grid Grid.Column="2" Name="RTChartGrid">
                <-- CUT -->

            </Grid>


        </Grid>


as per http://social.msdn.microsoft.com/Forums/en/wpf/thread/f7b6845d-f9d6-4f0d-aa88-a338641522ee


I simply attached a Loaded handler to the Datagrid and set all of the additional columns to a width of 0 and made them hidden.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜