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 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();
            if (SuspendUpdates)
            {
                childGrid.SuspendUpdates = true;
            }
            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;

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

            // done
            return(true);
        }
Beispiel #4
0
 private void ApplyParentStyles(C1FlexDataTree parent)
 {
     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 #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 (!SuspendUpdates && parent == null)
            {
                UpdateChildren();
            }
        }
Beispiel #6
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.SuspendUpdates = false;
             child.UpdatePosition();
         }
     }
 }
Beispiel #7
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 #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
        // customize grid display to show selected columns, captions, formats, and data maps
        void _flex_SetupColumns(object sender, System.EventArgs e)
        {
            // get grid that was just bound
            C1FlexDataTree grid = sender as C1FlexDataTree;

            if (grid == null || grid.DataSource == null)
            {
                return;
            }

            // get source DataTable
            CurrencyManager cm = (CurrencyManager)BindingContext[grid.DataSource, grid.DataMember];
            DataTable       dt = ((DataView)cm.List).Table;

            // apply custom column order, captions, format
            string[] columns = dt.ExtendedProperties["ShowColumns"] as string[];
            if (columns != null)
            {
                SetupColumns(grid, columns);
            }

            // apply custom data maps
            foreach (Column gridColumn in grid.Cols)
            {
                DataColumn dataColumn = dt.Columns[gridColumn.Name];
                if (dataColumn == null)
                {
                    continue;
                }
                gridColumn.DataMap = dataColumn.ExtendedProperties["DataMap"] as IDictionary;
                if (gridColumn.DataMap != null)
                {
                    gridColumn.TextAlign = TextAlignEnum.LeftCenter;
                }
            }

            // all done, autosize to show mapped data
            if (grid.AutoResize)
            {
                grid.AutoSizeCols(12);
            }
        }
Beispiel #11
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);
            }

            // ** fire before collapse event
            var e = new RowColEventArgs(row, -1);

            OnBeforeCollapse(e);
            if (e.Cancel)
            {
                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);

            // ** fire after collapse event
            OnAfterCollapse(e);

            // done
            return(true);
        }
Beispiel #12
0
        // expand all rows
        public void ExpandAll(int level)
        {
            bool needSuspendUpdates = !SuspendUpdates;

            if (needSuspendUpdates)
            {
                // stop redrawing
                SuspendUpdates = true;
            }

            // 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
            if (needSuspendUpdates)
            {
                SuspendUpdates = false;
            }
        }
Beispiel #13
0
        // apply column information to a grid
        // this will set the column positions, caption, format, and visibility
        // (any columns not included in the 'columns' array will not be displayed
        void SetupColumns(C1FlexDataTree grid, string[] columns)
        {
            // initialize column position
            int position = grid.Cols.Fixed;

            // apply column information
            foreach (string s in columns)
            {
                // split column info (name, caption, format)
                string[] columnInfo = s.Split(',');

                // move column to proper position based on its name
                Column column = grid.Cols[columnInfo[0].Trim()];
                if (column != null)
                {
                    column.Move(position);
                    position++;

                    // apply caption
                    if (columnInfo.Length > 1)
                    {
                        column.Caption = columnInfo[1].Trim();
                    }

                    // apply format
                    if (columnInfo.Length > 2)
                    {
                        column.Format = columnInfo[2].Trim();
                    }
                }
            }

            // hide all other columns
            for (int i = position; i < grid.Cols.Count; i++)
            {
                grid.Cols[i].Visible = false;
            }
        }
Beispiel #14
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
     this.button1 = new System.Windows.Forms.Button();
     this.button2 = new System.Windows.Forms.Button();
     this.button3 = new System.Windows.Forms.Button();
     this._flex   = new DataTree.C1FlexDataTree();
     ((System.ComponentModel.ISupportInitialize)(this._flex)).BeginInit();
     this.SuspendLayout();
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(10, 9);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(115, 28);
     this.button1.TabIndex = 2;
     this.button1.Text     = "Customers";
     this.button1.Click   += new System.EventHandler(this.button1_Click);
     //
     // button2
     //
     this.button2.Location = new System.Drawing.Point(134, 9);
     this.button2.Name     = "button2";
     this.button2.Size     = new System.Drawing.Size(116, 28);
     this.button2.TabIndex = 2;
     this.button2.Text     = "Orders";
     this.button2.Click   += new System.EventHandler(this.button2_Click);
     //
     // button3
     //
     this.button3.Location = new System.Drawing.Point(259, 9);
     this.button3.Name     = "button3";
     this.button3.Size     = new System.Drawing.Size(115, 28);
     this.button3.TabIndex = 2;
     this.button3.Text     = "Nothing";
     this.button3.Click   += new System.EventHandler(this.button3_Click);
     //
     // _flex
     //
     this._flex.AllowAddNew      = true;
     this._flex.AllowDelete      = true;
     this._flex.ColumnInfo       = "10,1,0,0,0,130,Columns:0{Width:34;Style:\"ImageAlign:RightCenter;\";}\t";
     this._flex.Dock             = System.Windows.Forms.DockStyle.Fill;
     this._flex.DrawMode         = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;
     this._flex.HighLight        = C1.Win.C1FlexGrid.HighLightEnum.WithFocus;
     this._flex.Location         = new System.Drawing.Point(0, 40);
     this._flex.Name             = "_flex";
     this._flex.Rows.Count       = 51;
     this._flex.Rows.DefaultSize = 26;
     this._flex.ShowCursor       = true;
     this._flex.Size             = new System.Drawing.Size(782, 415);
     this._flex.StyleInfo        = resources.GetString("_flex.StyleInfo");
     this._flex.TabIndex         = 1;
     this._flex.VisualStyle      = C1.Win.C1FlexGrid.VisualStyle.Office2010Black;
     //
     // Form1
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(7, 20);
     this.ClientSize        = new System.Drawing.Size(782, 455);
     this.Controls.Add(this.button1);
     this.Controls.Add(this._flex);
     this.Controls.Add(this.button2);
     this.Controls.Add(this.button3);
     this.Font          = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.Name          = "Form1";
     this.Padding       = new System.Windows.Forms.Padding(0, 40, 0, 0);
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
     this.Text          = "C1FlexGrid: Data Tree";
     this.Load         += new System.EventHandler(this.Form1_Load);
     ((System.ComponentModel.ISupportInitialize)(this._flex)).EndInit();
     this.ResumeLayout(false);
 }
Beispiel #15
0
            override protected void OnAfterSort(SortColEventArgs e)
            {
                C1FlexDataTree parent = Parent as C1FlexDataTree;

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

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