Beispiel #1
0
        /// <summary>
        /// Show child rows
        /// </summary>
        /// <param name="index">Which row to expand</param>
        /// <param name="maxDepth">How far down to expand</param>
        /// <returns></returns>
        protected int expand(int index, int maxDepth)
        {
            var rowInfo = expandedRowList[index];

            if (!rowInfo.HasChildRows || rowInfo.ExpandedChildRows.Count > 0 && maxDepth == 0)
            {
                return(0); // row already expanded, nothing to do
            }
            int rowsAdded = 0;

            if (rowInfo.ExpandedChildRows.Count == 0)
            {
                if (!rowInfo.ChildRowCount.HasValue)
                {
                    var e = new TreeDataGridViewChildRowCountNeededEventArgs(rowInfo.RowIndexHierarchy);
                    OnChildRowCountNeeded(e);
                    rowInfo.ChildRowCount = e.ChildRowCount;
                }

                var childRowList = new List <ExpandedRowList>(rowInfo.ChildRowCount.Value);
                for (int j = 0; j < rowInfo.ChildRowCount; ++j)
                {
                    //get the content of the child row and add it to list to be inserted
                    var childRowInfo       = new ExpandedRowList(rowInfo.RowIndexHierarchy, j);
                    var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, childRowInfo.RowIndexHierarchy);
                    CellValueNeeded(this, cellValueEventArgs);
                    childRowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount;
                    childRowInfo.HasChildRows  = cellValueEventArgs.HasChildRows;
                    childRowList.Add(childRowInfo);
                }

                //insert new rows into table
                rowInfo.ExpandedChildRows = childRowList;
                expandedRowList.InsertRange(index + 1, childRowList);
                rowsAdded = childRowList.Count;
            }

            //If more expansion is needed recurse back to the begining
            if (maxDepth > rowInfo.RowIndexHierarchy.Count)
            {
                for (int j = 0; j < rowInfo.ChildRowCount; ++j)
                {
                    rowsAdded += expand(index + rowsAdded + 1 - rowInfo.ChildRowCount.Value + j, maxDepth);
                }
            }

            return(rowsAdded);
        }
        /// <summary>
        /// Show child rows
        /// </summary>
        /// <param name="index">Which row to expand</param>
        /// <param name="maxDepth">How far down to expand</param>
        /// <returns></returns>
        protected int expand (int index, int maxDepth)
        {
            var rowInfo = expandedRowList[index];

            if (!rowInfo.HasChildRows || rowInfo.ExpandedChildRows.Count > 0 && maxDepth == 0)
                return 0; // row already expanded, nothing to do

            int rowsAdded = 0;
            if (rowInfo.ExpandedChildRows.Count == 0)
            {
                if (!rowInfo.ChildRowCount.HasValue)
                {
                    var e = new TreeDataGridViewChildRowCountNeededEventArgs(rowInfo.RowIndexHierarchy);
                    OnChildRowCountNeeded(e);
                    rowInfo.ChildRowCount = e.ChildRowCount;
                }

                var childRowList = new List<ExpandedRowList>(rowInfo.ChildRowCount.Value);
                for (int j = 0; j < rowInfo.ChildRowCount; ++j)
                {
                    //get the content of the child row and add it to list to be inserted
                    var childRowInfo = new ExpandedRowList(rowInfo.RowIndexHierarchy, j);
                    var cellValueEventArgs = new TreeDataGridViewCellValueEventArgs(0, childRowInfo.RowIndexHierarchy);
                    CellValueNeeded(this, cellValueEventArgs);
                    childRowInfo.ChildRowCount = cellValueEventArgs.ChildRowCount;
                    childRowInfo.HasChildRows = cellValueEventArgs.HasChildRows;
                    childRowList.Add(childRowInfo);
                }

                //insert new rows into table
                rowInfo.ExpandedChildRows = childRowList;
                expandedRowList.InsertRange(index + 1, childRowList);
                rowsAdded = childRowList.Count;
            }

            //If more expansion is needed recurse back to the begining
            if (maxDepth > rowInfo.RowIndexHierarchy.Count)
                for (int j = 0; j < rowInfo.ChildRowCount; ++j)
                    rowsAdded += expand(index + rowsAdded + 1 - rowInfo.ChildRowCount.Value + j, maxDepth);

            return rowsAdded;
        }