.NET WinForm程序,WinCE系统下,用Xenocode Postbuild混淆之后,DataGrid绑定List无法显示...

本文提供了一种将集合类转换为DataTable,进而将其绑定到DataGrid以解决特定问题的方法。步骤包括获取集合属性、创建DataTable、填充数据,并最终加载数据至DataGrid中。

解决方法:将List转为DataTable,然后绑定到DataGrid,即可解决。

 1         /// <summary>
 2         /// 将集合类转换成DataTable
 3         /// </summary>
 4         /// <param name="list">集合</param>
 5         public static DataTable ToDataTable(IList list)
 6         {
 7             DataTable result = new DataTable();
 8             if (list.Count > 0)
 9             {
10                 PropertyInfo[] propertys = list[0].GetType().GetProperties();
11                 foreach (PropertyInfo pi in propertys)
12                 {
13                     result.Columns.Add(pi.Name, pi.PropertyType);
14                 }
15 
16 
17                 for (int i = 0; i < list.Count; i++)
18                 {
19                     ArrayList tempList = new ArrayList();
20                     foreach (PropertyInfo pi in propertys)
21                     {
22                         object obj = pi.GetValue(list[i], null);
23                         tempList.Add(obj);
24                     }
25                     object[] array = tempList.ToArray();
26                     result.LoadDataRow(array, true);
27                 }
28             }
29             return result;
30         }

 

转载于:https://www.cnblogs.com/Tualatin/p/4269267.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值