c# : how to easily display a Dictionary<string, int>?
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; 开发者_StackOverflow中文版
/*Where mWordCount is the Dictionary<string, int> but nothing shows up. (It's a forms-app, not a web-app)*/
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 theDataTable
andDataSet
classes.- The
IBindingList
interface, such as theBindingList<(Of <(T>)>)
class.- The
IBindingListView
interface, such as theBindingSource
class.
精彩评论