Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change GridView header placement

I have a normal GridView, that displays grouped data. My goal is to move the header (a button) from the top of the group to the left of the group.

<GridView>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>

    <GridView.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid>
                        <Button Content="{Binding Title}"/>
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
            <GroupStyle.Panel>
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid ItemWidth="240" ItemHeight="160" Orientation="Vertical" Margin="0,0,80,0"/>
                </ItemsPanelTemplate>
            </GroupStyle.Panel>
        </GroupStyle>
    </GridView.GroupStyle>

    <GridView.ItemTemplate>
        <!-- item template -->
    </GridView.ItemTemplate>
</GridView>

An answer to this question Grouping GridView in Windows 8 Metro App - while not completely the same desired layout - says that the desired layout is not possible without adding an extra "dummy tile".

I'm wondering if it is possible to achieve my goal - to move the header from the top of the group to the left of the group - without such an extra "dummy tile".

like image 531
torjue Avatar asked Aug 24 '12 14:08

torjue


People also ask

How to set column header width in GridView?

Write a Css for GridView header position. 2. Add the Css in GridView's HeaderStyle tag. 3. Set column header width.

Why can't I sort the header column in a GridView?

This does not seem to work if you have things like "AllowSorting" set to true or if you have added other postback functionality to the header. If you have sorting enabled for instance, and you click on the header column to sort, the entire gridview disappears. You can try overflow css property.

Is it possible to add fixed-width columns to a GridView?

The 3-rd ASP.NET GridView controls (such as the ASPxGridView from DevExpress component vendor provide this functionality. None of these solutions works as expected. All of them rely on fixed-width columns and either separate header from rest of the table or use IE-specific top:expression (...) which does not work on any other browser. btw.

How to scroll vertically in a GridView?

GridView can be scrolled vertically. GridView doesn't have the ability to scroll. But if the GridView contains a larger number of rows or columns (say more than 100 rows and 15 columns), we want it to have scrollbars.


Video Answer


1 Answers

You need to edit the header container style. In Visual Studio, right-click the GridView and select

Edit Group Style -> Edit Generated Item Container (Container Style) -> Edit a Copy

You will see the Group Header, which is a Content Control, and the Group Items, which are an ItemsControl. Both are contained inside a grid that, in the default, is simple two rows. You can add a column, move the Group Header into Grid.Column=0 & Grid.Row=1 and you should be good to go.

like image 186
Jeff Brand Avatar answered Oct 04 '22 02:10

Jeff Brand