0

I have a dictionary

private Dictionary<int, data> mdata = new Dictionary<int, data>();

I would like to edit the Dictionary in the UI.

I think using with a DataGridView is a possibility.

How can I put the data from the dictionary into the DataGridView and after editing back into the dictionary?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    What UI framework? What data grid exactly? – Dennis Mar 24 '16 at 10:41
  • http://stackoverflow.com/questions/5204423/filling-wpf-datagrid-in-c-sharp-with-a-dictionary-string-string – Yanshof Mar 24 '16 at 10:41
  • There is no such thing as a 'datagird'. There are DataGrids and GridViews and DataGridViews, depending on what you do. Winforms? DataGridViews ! Did you see [this](http://stackoverflow.com/questions/1928567/using-a-dictionary-in-a-propertygrid)? – TaW Mar 24 '16 at 10:47
  • UI is User Interface – Peter.M Mar 24 '16 at 11:09
  • And its a dataGridViews – Peter.M Mar 24 '16 at 11:10
  • Yes, excactly a Winforms-Project – Peter.M Mar 24 '16 at 11:10
  • [DataGridView bound to a Dictionary](http://stackoverflow.com/questions/854953/datagridview-bound-to-a-dictionary) suggests using a DGV may not be the best way. Have you looked at the PropertyGrid answer suggested by @TaW? – stuartd Mar 24 '16 at 11:23

1 Answers1

0
dataGridView.DataSource =  (from d in dictionary
                             orderby d.Value
                             select new
                              {
                               d.Key,
                               d.Value
                             }).ToList();
Eminem
  • 7,206
  • 15
  • 53
  • 95