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

Binding dictionary to RadDataGrid

7 Answers 284 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Kelly
Top achievements
Rank 1
Kelly asked on 09 Oct 2017, 03:18 PM

I've got a standard string dictionary coming in and need to bind it to my grid. At the moment, I am trying to do this by manually adding columns, like so:

 

private void AddColumn(DataGridHeader header) {
    DataGridTextColumn column = new DataGridTextColumn();
 
    column.PropertyName = "Value"; // should return the dictionary value from what I've read
    column.Header = header.Name;
     //... etc ...
    _dataGrid.Columns.Add(column);
}

 

Unfortunately, it's not coming back right. The right number of columns is there, but there's nothing in them. Am I on the wrong track entirely? Also, is there a way to edit values with a dictionary source? TIA

7 Answers, 1 is accepted

Sort by
0
Kelly
Top achievements
Rank 1
answered on 09 Oct 2017, 06:47 PM
Let me clarify a little: an observable *collection* of string dictionaries, each of which has the same 4 entries (date, to, from, subject in the test I'm currently employing). The app in question needs to take whatever dictionary collection there is, and populate the columns accordingly. So any guidance would be fantastic. Thanks!
0
Nasko
Telerik team
answered on 12 Oct 2017, 08:57 AM
Hi Kelly,

From the provided description of your requirements it seems the way the data is provided to the DataGrid is not accurate. What we suggest you to do is to create a class that describes the data you want to visualize in the DataGrid - for example class Message with properties date, to, from, subject. After that create objects of Messages using the data from the Dictionaries and add this objects to an ObservableCollection of Messages - that collection you should bind to the ItemsSource of the control. Thus the desired columns with data will be created and everything should be visualized as expected.

Hope this helps.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kelly
Top achievements
Rank 1
answered on 12 Oct 2017, 01:01 PM
Unfortunately, due to the nature of the application, I don't know what kind of fields I'm going to have until I receive the dictionary from the VM. I have been experimenting these last couple of days with dynamic objects, but they don't seem to be bindable, and of course DataTable is not in UWP either. So, any suggestions would be most welcome.
0
Kelly
Top achievements
Rank 1
answered on 12 Oct 2017, 09:34 PM
So it looks like .net standard 2.0 will be bringing back Dataset/DataTable, among other things. Will the UWP version of RadDataGrid be able to bind to these like other versions do? Because if it can, that will make my life a lot easier.
0
Nasko
Telerik team
answered on 16 Oct 2017, 07:06 AM
Hello Kelly,

You are absolutely right that with .NET Standart 2.0 Dataset/DataTables will be supported. You can check the presentation of Daniel Jacobson and Chris Barker that demonstrates in real time how to visualize DataTable into our RadDataGrid:
https://channel9.msdn.com/Events/Windows/Windows-Developer-Day-Fall-Creators-Update/WinDev001
https://channel9.msdn.com/Events/dotnetConf/2017/T117

If using DataTables will work for you we suggest you to wait until the Fall Creators Update will be released (with that update UWP will support .NET Standart) and use the DataTables with out DataGrid.

Hope the provided information will be helpful for you.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kelly
Top achievements
Rank 1
answered on 20 Nov 2017, 05:29 PM

OK, so they finally deployed the Fall Creators Update to our machines. I now have a simple test program running build 16299 and 1.0.0.7 of the UWP UI toolset. 

I set up a RadDataGrid named dataGrid, and do the following in the back-end:

            DataTable foo = new DataTable("FooTable");
            dataGrid.ItemsSource = foo; // breaks here

Unfortunately, what I get is "InvalidOperationException: 'Specified data source not supported'."

Any ideas?

0
Nasko
Telerik team
answered on 21 Nov 2017, 08:54 AM
Hi Kelly,

Directly the DataTable could not be set - it should be cast to an IEnumerble collection. I suggest you to check the example demonstrated by Chris Barker in the video on the following link - the approach demonstrated is exactly how DataTables could be consumed by the DataGrid:
https://github.com/cbarkerms/DotNetStandardUWP

Hope this helps.

Regards,
Nasko
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataGrid
Asked by
Kelly
Top achievements
Rank 1
Answers by
Kelly
Top achievements
Rank 1
Nasko
Telerik team
Kelly
Top achievements
Rank 1
Share this question
or