我如何将DataGridview与Hashtable绑定 [英] How i can bind DataGridview with Hashtable

查看:161
本文介绍了我如何将DataGridview与Hashtable绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将DataGridview与Hashtable绑定

我做到了,但是我将对象存储在哈希表中,所以当我绑定对象时出现,但是我想要对象内部的内容(所有属性)

How i can bind DataGridview with Hashtable

I am do it but i store object in hashtable so when i bind the object appears but i want what inside object ( all property )

ht.Add("p", new Products { P_Name = "productA", P_Price = 20 });
         ht.Add("p2", new Products { P_Name = "productB", P_Price = 20 });
         dataGridView1.DataSource = ht.Cast<DictionaryEntry>()
                          .Select(x => new
                          {
                             // col = (from s in x.Value select new Products { P_Name, P_Price }),
                              Colum = x.Key.ToString(),
                              Colum1 = x.Value.ToString()
                          })
                          .ToList();

推荐答案

也许...
Maybe...
ht.Add("p", new Products { P_Name = "productA", P_Price = 20 });
         ht.Add("p2", new Products { P_Name = "productB", P_Price = 20 });
         dataGridView1.DataSource = ht.Cast<dictionaryentry>()
                          .Select(x => new
                          {
                             // col = (from s in x.Value select new Products { P_Name, P_Price }),
                              Colum = x.Key.ToString(),
                              Colum1 = x.Value.P_Name.ToString(),
                              Column2 = x.Value.P_Price.ToString()
                          })
                          .ToList();





请参阅下面的链接:

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/d4745e6e-fcb1-4083-8d4a-e654b5afa75a [ http://bytes.com/topic/c-sharp/answers/506707-binding- hashtable-datagridview [ ^ ]

http://www.dreamincode.net/forums/topic/79420-bind-hashtable -into-datagridview/ [ ^ ]
Hi,


See the link Below:

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/d4745e6e-fcb1-4083-8d4a-e654b5afa75a[^]

http://bytes.com/topic/c-sharp/answers/506707-binding-hashtable-datagridview[^]

http://www.dreamincode.net/forums/topic/79420-bind-hashtable-into-datagridview/[^]


这篇关于我如何将DataGridview与Hashtable绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆