Beispiel #1
0
        private void ResetChildren()
        {
            // clear any existing children
            for (int i = 0; i < Controls.Count; i++)
            {
                C1FlexDataTree childGrid = Controls[i] as C1FlexDataTree;
                if (childGrid != null)
                {
                    Controls.Remove(childGrid);
                    i--;
                }
            }

            // reset all row heights
            for (int i = 0; i < this.Rows.Count; i++)
            {
                Rows[i].Height   = -1;
                Rows[i].UserData = null;
            }

            // keep track of hierarchical column
            _colChild = null;
            foreach (Column col in Cols)
            {
                Type type = col.DataType;
                if (type != null && typeof(IList).IsAssignableFrom(type) && type != typeof(byte[]))
                {
                    _colChild = col;
                    break;
                }
            }

            // fire event to allow customization of master/child grids
            ParentGrid.OnSetupColumns(this);
        }
Beispiel #2
0
        // collapse row
        public bool CollapseRow(int row)
        {
            // sanity
            if (row < Rows.Fixed || row >= Rows.Count)
            {
                return(false);
            }

            // check that the row is expanded
            C1FlexDataTree childGrid = Rows[row].UserData as C1FlexDataTree;

            if (childGrid == null)
            {
                return(false);
            }

            // break references
            Rows[row].UserData = null;
            childGrid.Tag      = null;

            // clear child and remove it from parent
            childGrid.Controls.Clear();
            Controls.Remove(childGrid);

            // delete container row
            Rows.Remove(row + 1);

            // done
            return(true);
        }
Beispiel #3
0
        // expand all rows
        public void ExpandAll(int level)
        {
            // stop redrawing
            bool redraw = Redraw;

            // expand all child rows
            for (int r = Rows.Fixed; r < Rows.Count; r++)
            {
                bool expanded = ExpandRow(r);
                if (expanded)
                {
                    r++;
                }
            }

            // recurse to expand children
            if (level > 0)
            {
                foreach (Control ctl in this.Controls)
                {
                    C1FlexDataTree child = ctl as C1FlexDataTree;
                    if (child != null)
                    {
                        child.ExpandAll(level - 1);
                    }
                }
            }

            // done
            Redraw = redraw;
        }
Beispiel #4
0
        // expand row
        public bool ExpandRow(int row)
        {
            // sanity
            if (row < Rows.Fixed || row >= Rows.Count)
            {
                return(false);
            }

            // check that the row is not already expanded
            C1FlexDataTree childGrid = Rows[row].UserData as C1FlexDataTree;

            if (childGrid != null)
            {
                return(false);
            }

            // check that we have a data source for this row
            object dataSource = _colChild != null? _colChild[row] : null;

            if (!(dataSource is IBindingList))
            {
                return(false);
            }

            // add node row (unbound) to display child
            Rows.InsertNode(row + 1, -1);

            // make new row non-editable (it's just a placeholder)
            Rows[row + 1].AllowEditing = false;

            // create child grid
            childGrid            = new C1FlexDataTree();
            childGrid.Visible    = false;
            childGrid.ScrollBars = ScrollBars.Horizontal;

            // attach child grid to parent, set data source
            Controls.Add(childGrid);
            childGrid.DataSource = dataSource;

            // save references:
            // child grid Tag property contains a reference to the parent row
            // parent row UserData contains a reference to the child grid
            childGrid.Tag      = Rows[row];
            Rows[row].UserData = childGrid;

            // make child grid visible, move it into position
            childGrid.Visible = true;
            childGrid.UpdatePosition();
            childGrid.Focus();

            // done
            return(true);
        }
Beispiel #5
0
        // update position of child grids when size changes
        //
        // when the grid is resized, move child grids so they
        // stay in their proper position.
        //
        override protected void OnSizeChanged(EventArgs e)
        {
            // always call base implementation
            base.OnSizeChanged(e);

            // if this is the top-level grid, update position of child grids
            C1FlexDataTree parent = Parent as C1FlexDataTree;

            if (parent == null)
            {
                UpdateChildren();
            }
        }
Beispiel #6
0
            public GridHeader(C1FlexDataTree parent)
            {
                // initialize
                Dock        = DockStyle.Top;
                BorderStyle = C1.Win.C1FlexGrid.Util.BaseControls.BorderStyleEnum.None;
                Height      = parent.Rows[Rows.Fixed].Top;
                ScrollBars  = ScrollBars.None;

                // add to parent Controls collection
                parent.Controls.Add(this);

                // header grid uses parent as a DataSource, causing both grids to share
                // the same underlying grid model (rows/cols).
                DataSource = parent;
            }
Beispiel #7
0
        // update size/position of all child grids and of this grid within this parent.
        // this is called when the grid scrolls, when it's size changes, and when
        // rows or columns are added, removed, or resized.
        private void UpdateChildren()
        {
            // update position of all children
            for (int row = 0; row < Rows.Count; row++)
            {
                C1FlexDataTree child = Rows[row].UserData as C1FlexDataTree;
                if (child != null)
                {
                    child.UpdatePosition();
                }
            }

            // and update position of this grid within its parent
            UpdatePosition();
        }
Beispiel #8
0
        //--------------------------------------------------------------------------------
        #region ** overrides

        // initialize child grids by copying properties from parent
        // border style, colors, etc.
        override protected void OnParentChanged(EventArgs e)
        {
            // always call base implementation
            base.OnParentChanged(e);

            // copy properties from parent
            C1FlexDataTree parent = Parent as C1FlexDataTree;

            if (parent != null)
            {
                Cols[0].Width = parent.Cols[0].Width;
                ShowCursor    = parent.ShowCursor;
                AllowAddNew   = parent.AllowAddNew;
                AllowDelete   = parent.AllowDelete;
                BorderStyle   = parent.BorderStyle;
                Styles.ParseString(parent.Styles.BuildString(true));
            }
        }
Beispiel #9
0
        // update position of this child grid within its parent.
        // this is called by the UpdateChildren method above and also
        // when child grids are created.
        private void UpdatePosition()
        {
            // sanity
            C1FlexDataTree parent    = Parent as C1FlexDataTree;
            Row            parentRow = Tag as Row;

            if (parent == null || parentRow == null)
            {
                return;
            }

            // get cell rectangle
            int       row = parentRow.Index;
            Rectangle rc  = parent.GetCellRectDisplay(row, 0);

            // calculate child location and client size
            rc.X      = rc.Right;
            rc.Y      = rc.Bottom;
            rc.Width  = Cols[Cols.Count - 1].Right;
            rc.Width  = Math.Max(Cols[Cols.Count - 1].Right, parent.ScrollableRectangle.Width);
            rc.Height = Rows[Rows.Count - 1].Bottom;

            // make sure child grid width doesn't extend past parent client width
            int maxRight = parent.ClientSize.Width - 2;

            if (rc.Right > maxRight)
            {
                rc.Width = maxRight - rc.X;
            }

            // update size/position
            if (Location != rc.Location)
            {
                Location = rc.Location;
            }
            if (ClientSize != rc.Size)
            {
                ClientSize = rc.Size;
            }

            // update height of container row
            parent.Rows[row + 1].Height = Height;
        }
Beispiel #10
0
            override protected void OnAfterSort(SortColEventArgs e)
            {
                C1FlexDataTree parent = Parent as C1FlexDataTree;

                parent.OnAfterSort(e);
            }
Beispiel #11
0
            // keep grids synchronized
            override protected void OnAfterScroll(RangeEventArgs e)
            {
                C1FlexDataTree parent = Parent as C1FlexDataTree;

                parent.ScrollPosition = new Point(ScrollPosition.X, parent.ScrollPosition.Y);
            }