コード例 #1
0
ファイル: O2Forms.cs プロジェクト: pusp/o2platform
 // this is a more refined version of the above method: public static void populateControlItemCollectionWithArray(Object oLiveObject, String[] asArray)
 public static int populateWindowsControlWithList(Control targetControl, object itemsToAdd)
 {
     if (targetControl.okThread(delegate { populateWindowsControlWithList(targetControl, itemsToAdd); }))
     {
         object targetCollection = null;
         switch (targetControl.GetType().Name)
         {
             case "ListBox":
             case "ComboBox":
             case "ListView":
                 targetCollection = PublicDI.reflection.getProperty("Items", targetControl);
                 break;
             case "TreeView":
                 targetCollection = PublicDI.reflection.getProperty("Nodes", targetControl);
                 break;
             default:
                 PublicDI.log.error("in populateWindowsControlWithList, unsupported object type: {0}",
                              targetControl.GetType().Name);
                 break;
         }
         if (targetCollection != null)
         {
             PublicDI.reflection.invokeMethod_InstanceStaticPublicNonPublic(targetCollection, "Clear", new object[0]);
             foreach (object itemToAdd in (IEnumerable) itemsToAdd)
             {
                 switch (targetControl.GetType().Name)
                 {
                     case "ListBox":
                     case "ComboBox":
                         PublicDI.reflection.invokeMethod_InstanceStaticPublicNonPublic(targetCollection, "Add",
                                                                                  new[] {itemToAdd});
                         break;
                     case "ListView":
                         var listViewItem = new ListViewItem(itemToAdd.ToString())
                                                {
                                                    Name = itemToAdd.ToString(),
                                                    Tag = itemToAdd
                                                };
                         PublicDI.reflection.invokeMethod_InstanceStaticPublicNonPublic(targetCollection, "Add",
                                                                                  new[] {listViewItem});
                         break;
                     case "TreeView":
                         TreeNode treeNode = newTreeNode(itemToAdd.ToString(), itemToAdd.ToString(), 0, itemToAdd);
                         PublicDI.reflection.invokeMethod_InstanceStaticPublicNonPublic(targetCollection, "Add",
                                                                                  new[] {treeNode});
                         break;
                     default:
                         PublicDI.log.error("in populateWindowsControlWithList, unsupported object type: {0}",
                                      targetControl.GetType().Name);
                         break;
                 }
             }
             return
                 (int)
                 PublicDI.reflection.invokeMethod_InstanceStaticPublicNonPublic(targetCollection, "get_Count", null);
         }
     }
     return 0;
 }