SfDataGrid itemsource is Dictionary
I have a Dictionary<int, float> that I want to bind it to sfDataGrid where user can edit/add/delete keys and values.
How should I do that ?
SIGN IN To post a reply.
3 Replies
MA
Manikanda Akash Munisamy
Syncfusion Team
May 1, 2025 01:11 PM UTC
Hi John,
We have reviewed your scenario regarding binding a dictionary to SfDataGrid. This requirement can be achieved, and we have prepared a simple sample to demonstrate the approach. The sample has been attached for your reference.
For more details, please refer to the following Knowledge Base article:
Could you please review the sample and confirm whether it meets your requirement?
If we have misunderstood your request, or if your requirements differ, kindly share additional details. This will help us better understand your scenario and provide a more accurate solution.
Thank you for your continued support and cooperation.
Regards,
Manikanda Akash M
Attachment: SfDataGrid_Net80_5fcdc4b.zip
JO
John
May 2, 2025 03:55 AM UTC
Thats not what I asked, Your ItemSource is still ObservableCollection. I need ItemSource to be Dictionary, please read first post.
Something like this
var dictionary = new Dictionary<int, float>();
dictionary.Add(1, 85);
dictionary.Add(2, 96);
sfDataGrid.ItemSource = dictionary;
Where it shows, first column as Key and second column as Value
MS
Malini Selvarasu
Syncfusion Team
May 2, 2025 01:45 PM UTC
Hi John,
Based on the information provided, we understand that you are trying to bind a Dictionary as the ItemsSource for the SfDataGrid and would like to support adding and editing values. While this setup may seem straightforward, there are inherent limitations when using a Dictionary in this manner.
Based on the information provided, we understand that you are trying to bind a Dictionary as the ItemsSource for the SfDataGrid and would like to support adding and editing values. While this setup may seem straightforward, there are inherent limitations when using a Dictionary in this manner.
The primary issue is that both the Key and Value properties of a dictionary entry are immutable (read-only). As a result, the SfDataGrid does not support editing these values directly—particularly when the Key is displayed in the first column and the Value in the second column.
We have also evaluated the behavior of the default MSDN DataGrid and observed similar constraints. Due to these limitations, we recommend binding your data to the SfDataGrid using a List, ObservableCollection, or IEnumerable of custom objects instead. This approach provides full support for editing and adding new records.
For more details, please refer to the user documentation on data binding in SfDataGrid:
UG Link: Data Binding
Please let us know if you have any concerns or need further assistance. Thank you for your understanding.
Regards,
Malini Selvarasu
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
JO John
- May 1, 2025 01:50 AM UTC
- May 2, 2025 01:45 PM UTC