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

解决方法:将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         }

 

posted on 2015-02-03 10:02  图拉丁  阅读(252)  评论(0编辑  收藏  举报

导航