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

Binding Dictionary?

2 Answers 147 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lennart
Top achievements
Rank 1
Lennart asked on 10 Apr 2013, 07:41 AM
Hi

Im trying to bind a Dictionary to a Grid, but cant get the value out:

public Dictionary<int,string> Value1 { get; set; }

Value1 value;

(DataGrid.ItemSource =  value)

<telerikGrid:RadDataGrid x:Name="DataGrid">
 <telerikGrid:RadDataGrid.Columns>
  <telerikGrid:DataGridTextColumn PropertyName="Value1[1].Value" Header="Value"/> // I have try
  <telerikGrid:DataGridTextColumn PropertyName="Value1[1]" Header="Value"/> // and
 </telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>
Lennart

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 10 Apr 2013, 04:34 PM
Hi Lennart,

Thank you for your interest.

In its current version our RadDataGrid does not support binding to a Dictionary, but in our Q1 2013 SP1 which will be available next week, it will support such scenario.
As our RadDataGrid does not support binding to nested properties, the implementation should look like this:
<telerikGrid:RadDataGrid  ItemsSource="{Binding}"
                          AutoGenerateColumns="False">
    <telerikGrid:RadDataGrid.DataContext>
        <local:ViewModel/>
    </telerikGrid:RadDataGrid.DataContext>
    <telerikGrid:RadDataGrid.Columns>
        <telerikGrid:DataGridTextColumn Header="Key" PropertyName="Key"/>
        <telerikGrid:DataGridTextColumn Header="Value" PropertyName="Value"/>
    </telerikGrid:RadDataGrid.Columns>      
</telerikGrid:RadDataGrid>

Where our ViewModel is: 
public class ViewModel
 {
     public ViewModel()
     {
         Dictionary<int, string> myDictionary = new Dictionary<int, string>();
         myDictionary.Add(1, "first");
         myDictionary.Add(2, "second");
         myDictionary.Add(3, "third");
 
         this.DataContext = myDictionary;
     }
 }

I hope this helps. Let me know if you need further assistance.

 

All the best,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Lennart
Top achievements
Rank 1
answered on 11 Apr 2013, 08:42 AM
Hi Ivaylo

Thx alot for your answer, looking forward to see whats in the NeXT version.

Lennart
Tags
Grid for XAML
Asked by
Lennart
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Lennart
Top achievements
Rank 1
Share this question
or