Binding ItemsSource to a Dictionary not supported?

3 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 10 Dec 2013 Link to this post

    I was trying to bind my RadGridView ItemsSource to a Dictionary but I'm not seeing any data populate the grid.

    I've validated the data in my Dictionary but just will not bind to a RadGridView.

    Is this a known issue?  I'm able to bind it to an ObservableCollection, but not a Dictionary.

    Thanks, Rob.
  2. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 10 Dec 2013 Link to this post


    Key was to add ".Values" to the Binding for Dictionary collections.

    ItemsSource="{Binding Path=TransactionGroupDetails.Values}"

    However binding to Dictionary collection presents an odd problem, telerik:RadGridViewCommands.Delete will no longer fire if I have a button in my column.  In fact, the button is set to a disable state regardless.  See XAML:

    <telerik:GridViewDataColumn UniqueName="WaiveFeeButtonColumn" Header="Waive Fee" DataMemberBinding="{Binding WaiveFeeDescription}" FooterTextAlignment="Center" IsReadOnly="False" IsResizable="False" IsGroupable="False" IsFilterable="False" TextAlignment="Center" Width="100" Background="Transparent" HeaderTextAlignment="Center" IsSortable="False" IsReorderable="False" ShowDistinctFilters="False">
                                                <telerik:RadButton Content="Waive Fee"
                                                    Visibility="{Binding WaiveFeeDescription, Converter={StaticResource waiveFeeVisibilityConverter}}"
                                                    Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}"   
                                                    Template="{StaticResource RedDeleteButton}"
                                                    ToolTipService.ToolTip="Waive Fee"
                                                    Cursor="Hand" />

    If I use a List(Of T) (ObservableCollection), then the Delete will trigger and work as expected.  The Telerik RadGridView just doesn't seem to want to allow a delete if bound to a Dictionary.  So I still have a problem, any solution?

    Thanks, Rob.
  3. DevCraft R3 2016 release webinar banner
  4. Nick
    Nick avatar
    593 posts

    Posted 14 Dec 2013 Link to this post

    Hi Rob,

    The problem is that the Dictionarys Remove method takes only the key of the record you are trying to delete and the QueryableCollectionView passes the whole KeyValuePair resulting in either CanExecute to false, hence the disabled button, or an Argument exception when the command executes. 

    You can create your own custom command for deleting a dictionary record.

    Hope this helps! 

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top