When working with the DevExpress WPF GridControl, you can get an InfiniteGridSizeException thrown if the grid is in a container with potentially infinite height.

A consultation with Professor Google will show there are two suggested solutions - set MaxHeight on the GridControl to limit its height, or set the AllowInfiniteGridSize property to true. These two suggestions are repeated endlessly on the Developer Express support site.

There is, however, a simple third solution: Change the container of the GridControl so that it no longer has potentially infinite height.

For example, I’m hosting a GridControl within a NavBarControl and was getting the InfiniteGridSizeException. The NavBarGroup looked like this:

<dxn:NavBarGroup Header="Classifications"
                 DisplaySource="Content">
    <dxn:NavBarGroup.Content>
        <dxg:GridControl x:Name="grid"
                         ItemsSource="{Binding ClassificationListScreens}">
            ...
        </dxg:GridControl>
    </dxn:NavBarGroup.Content>
</dxn:NavBarGroup>

What I didn’t realise was that the NavBarGroup allows it’s content to have any height at all. Limiting the height of the content to the visible area just required setting the GroupScrollMode property:

<dxn:NavBarGroup Header="Classifications"
                 DisplaySource="Content"
                 GroupScrollMode="None">    <!-- Add this! -->
    <dxn:NavBarGroup.Content>
        <dxg:GridControl x:Name="grid"
                         ItemsSource="{Binding ClassificationListScreens}">
            ...
        </dxg:GridControl>
    </dxn:NavBarGroup.Content>
</dxn:NavBarGroup>

Once this was set, my GridControl stopped complaining and I was able to get on with building my application.

The lesson here is twofold:

Firstly, the exception really does indicate the source of the problem and direct you to the solution if you pay attention:

By default, an infinite grid height is not allowed since all grid rows will be rendered and hence the grid will work very slowly. To fix this issue, you should place the grid into a container that will give a finite height to the grid, or you should manually specify the grid’s Height or MaxHeight. Note that you can also avoid this exception by setting the GridControl.AllowInfiniteGridSize static property to True, but in that case the grid will run slowly.

Secondly, DeveloperExpress could do a better job of telling people how to solve the issue instead of just working around it.

Comments

blog comments powered by Disqus
Next Post
Why attend a user group meeting?  12 May 2013
Prior Post
Fixing Share to Mail App  13 Apr 2013
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
April 2013
2013