Esempio n. 1
0
        public static void ProcessCheckBoxTreeNodeChanged(TreeNode treeNode, bool isChecked)
        {
            CheckedItem checkedItem = (CheckedItem)treeNode.Tag;

            checkedItem.CurrentChecked = isChecked;
            checkedItem.IsChanged      = isChecked != checkedItem.OriginalChecked;

            treeNode.Tag = checkedItem;

            if (isChecked)
            {
                if (treeNode.Parent != null)
                {
                    treeNode.Parent.Checked = true;

                    ProcessCheckBoxTreeNodeChanged(treeNode.Parent, true);
                }
            }
            else
            {
                if (treeNode.Nodes.Count > 0)
                {
                    foreach (TreeNode childNode in treeNode.Nodes)
                    {
                        childNode.Checked = false;

                        ProcessCheckBoxTreeNodeChanged(childNode, false);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Collect Changed Item List From CheckedTreeView Control(Include Selected and Unselected)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="treeNodes"></param>
        /// <param name="selectedItemList"></param>
        /// <param name="unselectedItemList"></param>
        public static void CollectChangedItemList <T>(TreeNodeCollection treeNodes, List <T> selectedItemList, List <T> unselectedItemList)
        {
            if (treeNodes.Count > 0)
            {
                foreach (TreeNode treeNode in treeNodes)
                {
                    CheckedItem checkedItem = (CheckedItem)treeNode.Tag;

                    if (checkedItem.IsChanged)
                    {
                        if (checkedItem.Value != null && checkedItem.Value != DBNull.Value)
                        {
                            if (checkedItem.CurrentChecked)
                            {
                                selectedItemList.Add((T)Convert.ChangeType(checkedItem.Value, typeof(T), CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                unselectedItemList.Add((T)Convert.ChangeType(checkedItem.Value, typeof(T), CultureInfo.InvariantCulture));
                            }
                        }
                    }

                    CollectChangedItemList <T>(treeNode.Nodes, selectedItemList, unselectedItemList);
                }
            }
        }
Esempio n. 3
0
        public static void ProcessCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
        {
            CheckedListBox checkedListBox = (CheckedListBox)sender;

            CheckedItem checkedItem = (CheckedItem)checkedListBox.Items[e.Index];

            if (e.NewValue == CheckState.Checked)
            {
                checkedItem.CurrentChecked = true;
                checkedItem.IsChanged      = checkedItem.CurrentChecked != checkedItem.OriginalChecked;
            }
            else
            {
                checkedItem.CurrentChecked = false;
                checkedItem.IsChanged      = checkedItem.CurrentChecked != checkedItem.OriginalChecked;
            }

            checkedListBox.Items[e.Index] = checkedItem;
        }