本文介绍了我如何将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();

推荐答案

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();



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

09-17 04:28