示例#1
0
		internal int AddSorted(TreeNode node)
		{
			int pos = 0;
			string text = node.Text;
			if (childCount > 0)
			{
				Globalization.CompareInfo compare = Application.CurrentCulture.CompareInfo;
				// Simple optimization if added in sort order
				if (compare.Compare(children[(childCount - 1)].Text, text) <= 0)
					pos = childCount;
				else
				{
					// Binary Search
					int i = 0;
					int j = childCount;
					while (i < j)
					{
						int mid = (i + j) / 2;
						if (compare.Compare(children[mid].Text, text) <= 0)
							i = mid + 1;
						else
							i = mid;
					}
					pos = i;
				}
			}

			node.SortChildren();
			InsertNodeAt(pos, node);
			if (treeView != null && node == treeView.selectedNode)
			{
				treeView.SelectedNode = node;
			}
			return pos;
		}
示例#2
0
        internal int AddSorted(TreeNode node)
        {
            int    pos  = 0;
            string text = node.Text;

            if (childCount > 0)
            {
                Globalization.CompareInfo compare = Application.CurrentCulture.CompareInfo;
                // Simple optimization if added in sort order
                if (compare.Compare(children[(childCount - 1)].Text, text) <= 0)
                {
                    pos = childCount;
                }
                else
                {
                    // Binary Search
                    int i = 0;
                    int j = childCount;
                    while (i < j)
                    {
                        int mid = (i + j) / 2;
                        if (compare.Compare(children[mid].Text, text) <= 0)
                        {
                            i = mid + 1;
                        }
                        else
                        {
                            i = mid;
                        }
                    }
                    pos = i;
                }
            }

            node.SortChildren();
            InsertNodeAt(pos, node);
            if (treeView != null && node == treeView.selectedNode)
            {
                treeView.SelectedNode = node;
            }
            return(pos);
        }
 internal int AddSorted(TreeNode node)
 {
     int index = 0;
     string text = node.Text;
     System.Windows.Forms.TreeView treeView = this.TreeView;
     if (this.childCount > 0)
     {
         int num2;
         int childCount;
         int num4;
         if (treeView.TreeViewNodeSorter == null)
         {
             CompareInfo compareInfo = Application.CurrentCulture.CompareInfo;
             if (compareInfo.Compare(this.children[this.childCount - 1].Text, text) <= 0)
             {
                 index = this.childCount;
             }
             else
             {
                 num2 = 0;
                 childCount = this.childCount;
                 while (num2 < childCount)
                 {
                     num4 = (num2 + childCount) / 2;
                     if (compareInfo.Compare(this.children[num4].Text, text) <= 0)
                     {
                         num2 = num4 + 1;
                     }
                     else
                     {
                         childCount = num4;
                     }
                 }
                 index = num2;
             }
         }
         else
         {
             IComparer treeViewNodeSorter = treeView.TreeViewNodeSorter;
             num2 = 0;
             childCount = this.childCount;
             while (num2 < childCount)
             {
                 num4 = (num2 + childCount) / 2;
                 if (treeViewNodeSorter.Compare(this.children[num4], node) <= 0)
                 {
                     num2 = num4 + 1;
                 }
                 else
                 {
                     childCount = num4;
                 }
             }
             index = num2;
         }
     }
     node.SortChildren(treeView);
     this.InsertNodeAt(index, node);
     return index;
 }
示例#4
0
文件: TreeNode.cs 项目: JianwenSun/cc
        /// <include file='doc\TreeNode.uex' path='docs/doc[@for="TreeNode.AddSorted"]/*' />
        /// <devdoc>
        ///     Adds a new child node at the appropriate sorted position
        /// </devdoc>
        /// <internalonly/>
        internal int AddSorted(TreeNode node) {
            int index = 0;
            int iMin, iLim, iT;
            string nodeText = node.Text;
            TreeView parentTreeView = TreeView;
            
            if (childCount > 0) {
                if (parentTreeView.TreeViewNodeSorter == null)
                {
                    CompareInfo compare = Application.CurrentCulture.CompareInfo;

                    // Optimize for the case where they're already sorted
                    if (compare.Compare(children[childCount-1].Text, nodeText) <= 0)
                        index = childCount;
                    else {
                        // Insert at appropriate sorted spot
                        for (iMin = 0, iLim = childCount; iMin < iLim;) {
                            iT = (iMin + iLim) / 2;
                            if (compare.Compare(children[iT].Text, nodeText) <= 0)
                                iMin = iT + 1;
                            else
                                iLim = iT;
                        }
                        index = iMin;
                    }
                }
                else 
                {
                    IComparer sorter = parentTreeView.TreeViewNodeSorter;
                    // Insert at appropriate sorted spot
                    for (iMin = 0, iLim = childCount; iMin < iLim;) {
                        iT = (iMin + iLim) / 2;
                        if (sorter.Compare(children[iT] /*previous*/, node/*current*/) <= 0)
                            iMin = iT + 1;
                        else
                            iLim = iT;
                    }
                    index = iMin;
                }
            }
           
            node.SortChildren(parentTreeView);
            InsertNodeAt(index, node);
            
            return index;
        }