views:

248

answers:

1

I have a dictionary that I want to show in a form. What's the easiest way to do this ?

Preferrably I'd like to show a control where I can sort using the int-value. I've tried a DataGridView but nothing shows up, I must be doing something wrong...

Code:

mDataGridView.DataSource = mWordCount; 
/*Where mWordCount is the Dictionary<string, int> but nothing shows up. (It's a forms-app, not a web-app)*/
+4  A: 

Try mWordCount.ToList() and see what happens.

Explanation is here:

The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

  • The IList interface, including one-dimensional arrays.
  • The IListSource interface, such as the DataTable and DataSet classes.
  • The IBindingList interface, such as the BindingList<(Of <(T>)>) class.
  • The IBindingListView interface, such as the BindingSource class.
Robert Harvey
Works like a charm, thank you !Can you by any chance also tell me how to display the datagrid sorted by the int-value ?
Led
The `SortedColumn` property should allow you to do that: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.sortedcolumn.aspx
Robert Harvey