This is a migrated thread and some comments may be shown as answers.

Binding ItemsSource to a Dictionary not supported?

2 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 10 Dec 2013, 07:29 PM
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 Answers, 1 is accepted

Sort by
0
Rob Ainscough
Top achievements
Rank 1
answered on 10 Dec 2013, 11:31 PM
[PARTIAL SOLUTION]

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:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <telerik:RadButton Content="Waive Fee"
                                                Padding="2"
                                                FontWeight="Bold"
                                                FontSize="12"
                                                Visibility="{Binding WaiveFeeDescription, Converter={StaticResource waiveFeeVisibilityConverter}}"
                                                Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}"   
                                                Template="{StaticResource RedDeleteButton}"
                                                ToolTipService.ToolTip="Waive Fee"
                                                Cursor="Hand" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                </telerik:GridViewDataColumn>

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.
0
Nick
Telerik team
answered on 14 Dec 2013, 01:26 PM
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! 

Regards,
Nik
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
Tags
GridView
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
Rob Ainscough
Top achievements
Rank 1
Nick
Telerik team
Share this question
or