private void AddMenuItems(int currGroupIndex, ref int currentListIndex, ToolStripItemCollection currNodes, string prevGroupByField)
        {
            IList innerList = this.m_currencyManager.List;
            System.ComponentModel.PropertyDescriptor pdPrevGroupBy = null;
            string prevGroupByValue = null;

            SPTreeNodeGroup currGroup;

            if (prevGroupByField != "")
            {
                pdPrevGroupBy = this.m_currencyManager.GetItemProperties()[prevGroupByField];
            }

            currGroupIndex++;

            if (treeGroups.Count > currGroupIndex)
            {
                currGroup = (SPTreeNodeGroup) (treeGroups[currGroupIndex]);
                PropertyDescriptor pdGroupBy = null;
                PropertyDescriptor pdValue = null;
                PropertyDescriptor pdDisplay = null;

                pdGroupBy = this.m_currencyManager.GetItemProperties()[currGroup.GroupBy];
                pdValue = this.m_currencyManager.GetItemProperties()[currGroup.ValueMember];
                pdDisplay = this.m_currencyManager.GetItemProperties()[currGroup.DisplayMember];

                string currGroupBy = null;

                if (innerList.Count > currentListIndex)
                {
                    if (pdPrevGroupBy != null)
                    {
                        prevGroupByValue = pdPrevGroupBy.GetValue(innerList[currentListIndex]).ToString();
                    }

                    MenuStripItem myFirstNode = null;
                    object currObject = null;

                    while ((currentListIndex < innerList.Count) && (pdPrevGroupBy != null) && (pdPrevGroupBy.GetValue(innerList[currentListIndex]).ToString() == prevGroupByValue))
                    {
                        currObject = innerList[currentListIndex];
                        if (pdGroupBy.GetValue(currObject).ToString() != currGroupBy)
                        {
                            currGroupBy = pdGroupBy.GetValue(currObject).ToString();

                            myFirstNode = new MenuStripItem(currGroup.Name, pdDisplay.GetValue(currObject).ToString(), currObject, pdValue.GetValue(innerList[currentListIndex]), currGroup.ImageIndex, currentListIndex);

                            currNodes.Add(myFirstNode);
                        }
                        else
                        {
                            AddMenuItems(currGroupIndex, ref currentListIndex, this.Items, currGroup.GroupBy);
                        }
                    }
                }
            }
            else
            {
                MenuStripItem myNewLeafNode;
                object currObject = this.m_currencyManager.List[currentListIndex];

                if ((this.DisplayMember != null) && (this.ValueMember != null) && (this.DisplayMember != "") && (this.ValueMember != ""))
                {
                    PropertyDescriptor pdDisplayloc = this.m_currencyManager.GetItemProperties()[this.DisplayMember];
                    PropertyDescriptor pdValueloc = this.m_currencyManager.GetItemProperties()[this.ValueMember];

                    if (this.Tag == null)
                    {
                        myNewLeafNode = new MenuStripItem("", pdDisplayloc.GetValue(currObject).ToString(), currObject, pdValueloc.GetValue(currObject), currentListIndex);
                    }
                    else
                    {
                        myNewLeafNode = new MenuStripItem(this.Tag.ToString(), pdDisplayloc.GetValue(currObject).ToString(), currObject, pdValueloc.GetValue(currObject), currentListIndex);
                    }
                }
                else
                {
                    myNewLeafNode = new MenuStripItem("", currentListIndex.ToString(), currObject, currObject, currentListIndex, currentListIndex);
                }

                currNodes.Add(myNewLeafNode);
                currentListIndex++;
            }
        }
        public void BuildTree()
        {
            this.Items.Clear();
            if ((this.m_currencyManager != null) && (this.m_currencyManager.List != null))
            {
                IList innerList = this.m_currencyManager.List;
                ToolStripItemCollection currNode = this.Items;
                int currGroupIndex = 0;
                int currListIndex = 0;

                if (this.treeGroups.Count > currGroupIndex)
                {
                    SPTreeNodeGroup currGroup = (SPTreeNodeGroup) (treeGroups[currGroupIndex]);
                    MenuStripItem myFirstNode = null;
                    PropertyDescriptor pdGroupBy;
                    PropertyDescriptor pdValue;
                    PropertyDescriptor pdDisplay;

                    pdGroupBy = this.m_currencyManager.GetItemProperties()[currGroup.GroupBy];
                    pdValue = this.m_currencyManager.GetItemProperties()[currGroup.ValueMember];
                    pdDisplay = this.m_currencyManager.GetItemProperties()[currGroup.DisplayMember];

                    string currGroupBy = null;
                    if (innerList.Count > currListIndex)
                    {
                        object currObject;
                        while (currListIndex < innerList.Count)
                        {
                            currObject = innerList[currListIndex];
                            if (pdGroupBy.GetValue(currObject).ToString() != currGroupBy)
                            {
                                currGroupBy = pdGroupBy.GetValue(currObject).ToString();

                                myFirstNode = new MenuStripItem(currGroup.Name, pdDisplay.GetValue(currObject).ToString(), currObject, pdValue.GetValue(innerList[currListIndex]), currGroup.ImageIndex, currListIndex);

                                currNode.Add((ToolStripItem) myFirstNode);
                            }
                            else
                            {
                                AddMenuItems(currGroupIndex, ref currListIndex, this.Items, currGroup.GroupBy);
                            }
                        } // end while
                    } // end if
                }
                else
                {
                    while (currListIndex < innerList.Count)
                    {
                        AddMenuItems(currGroupIndex, ref currListIndex, this.Items, "");
                    }
                } // end else

            } // end if
        }