c#:如何轻松显示字典

发布于 2024-08-20 01:17:17 字数 308 浏览 3 评论 0原文

我有一本字典,我想以某种形式显示。 做到这一点最简单的方法是什么?

我最好想展示一个可以使用 int 值进行排序的控件。 我尝试过 DataGridView 但没有任何显示,我一定做错了什么......

代码:

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

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)*/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2024-08-27 01:17:17

尝试 mWordCount.ToList() 看看会发生什么。

说明位于此处

DataGridView类支持
标准 Windows 窗体数据绑定
模型。这意味着数据源可以
是实现以下之一的任何类型
以下接口:

  • IList 接口,包括一维数组。
  • IListSource 接口,例如 DataTableDataSet
    类。
  • IBindingList 接口,例如 BindingList<(Of <(T>)>)
    类。
  • IBindingListView 接口,例如 BindingSource 类。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文