コード例 #1
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()
        {
            try
            {
                // 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();
                    }
                }
            }
            catch
            {
            }

            // and update position of this grid within its parent
            UpdatePosition();
        }
コード例 #2
0
        // expand/collapse child grid
        //
        // if the user clicks the icons (drawn in the method above), either
        // create a child grid (and bind it to the detail records), or remove
        // the existing one.
        //
        override protected void OnBeforeMouseDown(BeforeMouseDownEventArgs e)
        {
            // always call base implementation
            base.OnBeforeMouseDown(e);

            // check that it's the Left button and that we have a hierarchy
            if (e.Button != MouseButtons.Left || _colChild == null)
            {
                return;
            }

            // check that it's a row header cell
            HitTestInfo hit = HitTest(e.X, e.Y);

            if (hit.Type != HitTestTypeEnum.RowHeader || hit.Row < Rows.Fixed)
            {
                return;
            }

            // check that the click was over the collapse/expand icon
            if (e.X < Cols[0].Right - (Glyphs[GlyphEnum.Collapsed].Width + 4) || _colChild[hit.Row] == null)
            {
                return;
            }

            // all checks OK, cancel click before proceeding
            e.Cancel = true;
            Select(hit.Row, Cols.Fixed, hit.Row, Cols.Count - 1, false);

            // create and show child grid
            if (Rows[hit.Row].UserData == null)
            {
                // create child grid
                C1FlexDataTree childGrid = new C1FlexDataTree();
                childGrid.Visible    = false;
                childGrid.ScrollBars = ScrollBars.Horizontal;

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

                childGrid.ApplyParentStyles(this);
                childGrid.DataSource = _colChild[hit.Row];

                // 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[hit.Row];
                Rows[hit.Row].UserData = childGrid;

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

                // move child grid into position, make it visible
                childGrid.UpdatePosition();
                childGrid.Visible = true;
                childGrid.Focus();
            }
            else             // hide and delete child grid
            {
                // get child grid
                C1FlexDataTree childGrid = (C1FlexDataTree)Rows[hit.Row].UserData;

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

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

                // delete container row
                var removeRowIndex = hit.Row + 1;
                if (Rows.Count > removeRowIndex)
                {
                    Rows.Remove(removeRowIndex);
                }
            }
        }