开发者

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 the DataTable and DataSet classes.
  • The IBindingList interface, such as the BindingList<(Of <(T>)>) class.
  • The IBindingListView interface, such as the BindingSource class.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜