Home Forums WPF controls Xceed DataGrid for WPF Datagrid Column visibility – Collection was modified; enumeration operation may not execute.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #40273 |

    Hello,

     I’ve got a column in a datagrid which shouldn’t always be visible. So I created a binding for the Visible property as you see below:


    <xcdg:Column Title=”Eigen Omschrijving”  AllowSort=”False” ReadOnly=”True” FieldName=”EigenOmschrijving” Width=”160″

    Visible=”{Binding Path=(utilsCommon:ReferentieData.Instance).IsRubriekenEigenOmschrijvingGebruikt}” />

     

    However, in runtime, I receive following System.Windows.Threading.DispatcherUnhandledException: “Collection was modified; enumeration operation may not execute.”

    Can you guide me on what to do?

    Imported from legacy forums. Posted by Ben (had 1365 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Ben,

    The binding expression you are using is not complete. To bind a column’s visibility to a boolean property, you should use a converter. You could do a quick search online to get the correct syntax of the binding expression which fit your needs. However, keep in mind that the DataGridColumn is not a part of the visual tree(not a FrameworkElement). Thus, the source property of your binding has to be a StaticResource. You may want to check the following link to see an example:

    http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 449 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your help but I believe it’s not the problem. 

    – If I look into the properties of the Xceed column, I can see clearly that the Visible property is in fact a boolean property so I wouldn’t expect a problem there?

    – The binding is a binding with a class with a Singleton property, which works in all other screens. It’s only in combination with the DataGrid’s Column of Xceed that I get this problem. Do you have an other suggestion?

    Imported from legacy forums. Posted by Ben (had 277 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Ben,

    Even the Column class has a Boolean Visible property, binding to that property is not the same as binding to the visible property of any other class that belongs to the visual tree. As I mentioned before, the Column class is special, since it is not a FrameworkElement and does not belong to the visual tree. That could be the reason why your binding works fine with other classes but not with the Column one. Unfortunately, the only workaround I can think about right now is to use a StaticResource as a source of your binding.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 950 views)

    knet
    Participant
    Post count: 1

    Dears,
    i have same exception,
    i have grid that binding on list, and one of columns of grid has check box and i need to show and hide this column based on property when screen initiated, so i use binding on property with converter .
    but when adding this view to windows region by IRegionManager (Member of Microsoft.Practices.Prism.Regions) generate this exception. System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

    here xaml
    <xcdg:Column FieldName=”IsChecked” Visible=”{Binding GroupActionsVisibility, Converter={StaticResource visibilityToBooleanConverter}}” AllowSort=”False” Title=”#” ReadOnly=”False” CellHorizontalContentAlignment=”Center”>
    <xcdg:Column.TitleTemplate>
    <DataTemplate>
    <CheckBox x:Name=”chkSelectAll” Click=”ChkClick” IsChecked=”{Binding Path=DataContext.IsAllSelected, Source={x:Reference Name=ScreenName}}” Margin=”2,0,0,0″ Content=”{Binding Path=DataContext.SelectionModeName, Source={x:Reference Name=ScreenName} }” VerticalAlignment=”Center” HorizontalAlignment=”Left”/>
    </DataTemplate>
    </xcdg:Column.TitleTemplate>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <CheckBox x:Name=”singleCheck” IsChecked=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:DataRow}}, Path=DataContext.IsChecked}” Click=”CheckCellClick”/>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    </xcdg:Column>

    Thanks

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.