Esempio n. 1
0
        /// <summary>
        /// Apply more complex/recursive checks to a tree node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="newStates">The new states.</param>
        public void ChangeNodesCheckStates(
            TreeNode node,
            NodesCheckState newStates)
        {
            if (node == null)
            {
                throw new ArgumentNullException(@"node");
            }
            else
            {
                switch (newStates)
                {
                case NodesCheckState.CheckAllChilds:
                    DeepSetCheckState(node, CheckState.Checked);
                    break;

                case NodesCheckState.UncheckAllChilds:
                    DeepSetCheckState(node, CheckState.Unchecked);
                    break;

                case NodesCheckState.UpdateStateFromChilds:
                    int checkedChildCount =
                        DeepCountChildsWithState(
                            node,
                            CheckState.Checked);
                    int uncheckedChildCount =
                        DeepCountChildsWithState(
                            node,
                            CheckState.Unchecked);
                    int indeterminateChildCount =
                        DeepCountChildsWithState(
                            node,
                            CheckState.Indeterminate);

                    if (indeterminateChildCount > 0)
                    {
                        InternalSetNodeCheckState(
                            node,
                            CheckState.Indeterminate);
                    }
                    else
                    {
                        if (checkedChildCount > 0)
                        {
                            if (uncheckedChildCount > 0)
                            {
                                InternalSetNodeCheckState(
                                    node,
                                    CheckState.Indeterminate);
                            }
                            else
                            {
                                InternalSetNodeCheckState(
                                    node,
                                    CheckState.Checked);
                            }
                        }
                        else
                        {
                            InternalSetNodeCheckState(
                                node,
                                CheckState.Unchecked);
                        }
                    }
                    break;

                case NodesCheckState.UpdateParentStates:
                    node = node.Parent;
                    while (node != null)
                    {
                        ChangeNodesCheckStates(
                            node,
                            NodesCheckState.UpdateStateFromChilds);

                        node = node.Parent;
                    }
                    break;

                default:
                    Debug.Assert(
                        false,
                        string.Format(
                            @"Unknown NodesCheckState enum value.",
                            newStates));
                    break;
                }
            }
        }
		/// <summary>
		/// Apply more complex/recursive checks to a tree node.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="newStates">The new states.</param>
		public void ChangeNodesCheckStates(
			TreeNode node,
			NodesCheckState newStates )
		{
			if ( node == null )
			{
				throw new ArgumentNullException( @"node" );
			}
			else
			{
				switch ( newStates )
				{
					case NodesCheckState.CheckAllChilds:
						DeepSetCheckState( node, CheckState.Checked );
						break;
					case NodesCheckState.UncheckAllChilds:
						DeepSetCheckState( node, CheckState.Unchecked );
						break;
					case NodesCheckState.UpdateStateFromChilds:
						int checkedChildCount =
							DeepCountChildsWithState(
							node,
							CheckState.Checked );
						int uncheckedChildCount =
							DeepCountChildsWithState(
							node,
							CheckState.Unchecked );
						int indeterminateChildCount =
							DeepCountChildsWithState(
							node,
							CheckState.Indeterminate );

						if ( indeterminateChildCount > 0 )
						{
							InternalSetNodeCheckState(
								node,
								CheckState.Indeterminate );
						}
						else
						{
							if ( checkedChildCount > 0 )
							{
								if ( uncheckedChildCount > 0 )
								{
									InternalSetNodeCheckState(
										node,
										CheckState.Indeterminate );
								}
								else
								{
									InternalSetNodeCheckState(
										node,
										CheckState.Checked );
								}
							}
							else
							{
								InternalSetNodeCheckState(
									node,
									CheckState.Unchecked );
							}
						}
						break;

					case NodesCheckState.UpdateParentStates:
						node = node.Parent;
						while ( node != null )
						{
							ChangeNodesCheckStates(
								node,
								NodesCheckState.UpdateStateFromChilds );

							node = node.Parent;
						}
						break;

					default:
						Debug.Assert(
							false,
							string.Format(
							@"Unknown NodesCheckState enum value.",
							newStates ) );
						break;
				}
			}
		}