private int GetLevel(DataGridViewColumnNode columnInfo)
        {
            int level = 0;

            SubGetLevel(columnInfo, ref level);
            return(level);
        }
示例#2
0
        private void btnAddSub_Click(object sender, EventArgs e)
        {
            TreeNode tnParent = treeView1.SelectedNode;

            if (tnParent == null)
            {
                tnParent = rootNode;
            }

            List <string> lstColumnName = GetGetLstDgvcName();
            string        name          = PublicMethods.CreateNewName(lstColumnName.ToArray(), "column");

            DataGridViewColumnNode hwvDgvc = new DataGridViewColumnNode();

            hwvDgvc.Name = name;

            TreeNode tn = new TreeNode();

            tn.Text = hwvDgvc.Text;
            tn.Tag  = hwvDgvc;

            tnParent.Nodes.Add(tn);
            tnParent.Expand();

            treeView1.SelectedNode = tn;
            //this.propertyGrid1.Focus();
        }
        ///// <summary>
        ///// 获得合并标题字段的宽度--获得组合节点对应宽度
        ///// </summary>
        ///// <param name="node">字段节点</param>
        ///// <returns>字段宽度</returns>
        ///// <remarks></remarks>
        //private int GetUnitHeaderWidth(DataGridViewColumnNode node, int VisibleColumnsCount)
        //{
        //    //获得非最底层字段的宽度
        //    int uhWidth = 0;
        //    //获得最底层字段的宽度
        //    if (node.IsLeafColumn)
        //    {
        //        //当前序号
        //        int index = lstLeafColumn.IndexOf(node);
        //        int index2 = GetColumnListNodeIndex(node);
        //        //if (index < VisibleColumnsCount)
        //        uhWidth = this.Columns[index2].Width;

        //        return uhWidth;
        //    }

        //    for (int i = 0; i < node.ChildColumns.Count; i++)
        //    {
        //        uhWidth += GetUnitHeaderWidth(node.ChildColumns[i], VisibleColumnsCount);
        //    }
        //    return uhWidth;
        //}

        /// <summary>
        /// 获得合并标题字段的宽度--获得组合节点对应宽度
        /// </summary>
        /// <param name="node">字段节点</param>
        /// <returns>字段宽度</returns>
        /// <remarks></remarks>
        private int GetUnitHeaderWidth(DataGridViewColumnNode node)
        {
            //获得非最底层字段的宽度
            int uhWidth = 0;

            //获得最底层字段的宽度
            if (node.IsLeafColumn)
            {
                //当前序号
                //int index = lstLeafColumn.IndexOf(node);
                int index2 = GetColumnListNodeIndex(node);
                if (index2 < this.Columns.Count)
                {
                    uhWidth = this.Columns[index2].Width;
                }

                return(uhWidth);
            }

            for (int i = 0; i < node.ChildColumns.Count; i++)
            {
                uhWidth += GetUnitHeaderWidth(node.ChildColumns[i]);
            }
            return(uhWidth);
        }
示例#4
0
        public FrmTreeHeadColumnsEdit(DataGridViewColumnNode hwvDgvc)
        {
            InitializeComponent();
            rootColumn = hwvDgvc;

            rootNode = treeView1.Nodes[0];
        }
        public void AddChildColumn(string text)
        {
            DataGridViewColumnNode hwvDgvc = new DataGridViewColumnNode();

            hwvDgvc.text = text;
            hwvDgvc.name = text;
            this.childColumns.Add(hwvDgvc);
        }
示例#6
0
        private DataGridViewColumnNode GetHWVDataGridViewColumn()
        {
            DataGridViewColumnNode dgvc = new DataGridViewColumnNode();

            SubGetHWVDataGridViewColumn(rootNode, ref dgvc);

            return(dgvc);
        }
        /// <summary>
        /// 浅复制
        /// </summary>
        /// <returns></returns>
        public DataGridViewColumnNode Clone()
        {
            DataGridViewColumnNode hwvDGVC = new DataGridViewColumnNode();

            hwvDGVC.text = this.text;
            hwvDGVC.name = this.name;

            return(hwvDGVC);
        }
        public void SetHeaderText(string columnName, string newColumnText)
        {
            DataGridViewColumnNode dgvcn2 = GetDataGridViewColumnNode(columnName);

            if (dgvcn2 != null)
            {
                dgvcn2.Text = newColumnText;
            }
        }
示例#9
0
        private void SubGetHWVDataGridViewColumn(TreeNode tnParent, ref DataGridViewColumnNode dgvcParent)
        {
            foreach (TreeNode tn in tnParent.Nodes)
            {
                DataGridViewColumnNode dgvc = tn.Tag as DataGridViewColumnNode;
                dgvcParent.AddChildColumn(dgvc);

                SubGetHWVDataGridViewColumn(tn, ref dgvc);
            }
        }
        private void SubGetLevel(DataGridViewColumnNode columnInfo, ref int level)
        {
            if (columnInfo.parent == null)
            {
                return;
            }

            level++;
            SubGetLevel(columnInfo.parent, ref level);
        }
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            DataGridViewColumnNode hwvDataGridViewColumn = value as DataGridViewColumnNode;

            if (hwvDataGridViewColumn == null || hwvDataGridViewColumn.IsLeafColumn == true)
            {
                return("");
            }

            return("复杂表头");
        }
示例#12
0
        public string GetHeaderText(string columnName)
        {
            DataGridViewColumnNode dgvcn2 = GetDataGridViewColumnNode(columnName);

            if (dgvcn2 != null)
            {
                return(dgvcn2.Text);
            }

            return(null);
        }
示例#13
0
 /// <summary>
 /// 获得底层节点对应的索引
 /// </summary>
 ///' <param name="node">底层字段节点</param>
 /// <returns>索引</returns>
 /// <remarks></remarks>
 private int GetColumnListNodeIndex(DataGridViewColumnNode node)
 {
     //for (int i = 0; i <= _columnList.Count - 1; i++)
     for (int i = 0; i < lstLeafColumn.Count; i++)
     {
         if (lstLeafColumn[i].Equals(node))
         {
             return(i);
         }
     }
     return(-1);
 }
        public void RemoveChildColumn(DataGridViewColumnNode hwvDgvc)
        {
            if (!childColumns.Contains(hwvDgvc))
            {
                return;
            }

            childColumns.Remove(hwvDgvc);
            if (TreeHeadColumnChanged != null)
            {
                TreeHeadColumnChanged(null, null);
            }
        }
 private void SubGetLstLeafColumn(DataGridViewColumnNode dgvc, ref List <DataGridViewColumnNode> lstLeafColumn)
 {
     if (dgvc.IsLeafColumn)
     {
         lstLeafColumn.Add(dgvc);
         return;
     }
     for (int i = 0; i < dgvc.childColumns.Count; i++)
     {
         DataGridViewColumnNode item = dgvc.ChildColumns[i];
         SubGetLstLeafColumn(item, ref lstLeafColumn);
     }
 }
示例#16
0
        private void SubGetGetLstDgvcName(TreeNode tn, ref List <string> lstColumnName)
        {
            foreach (TreeNode item in tn.Nodes)
            {
                DataGridViewColumnNode hwvDgvc = item.Tag as DataGridViewColumnNode;
                if (!lstColumnName.Contains(hwvDgvc.Name))
                {
                    lstColumnName.Add(hwvDgvc.Name);
                }

                SubGetGetLstDgvcName(item, ref lstColumnName);
            }
        }
        public void AddChildColumn(DataGridViewColumnNode hwvDgvc)
        {
            if (hwvDgvc == null)
            {
                return;
            }
            if (childColumns.Contains(hwvDgvc))
            {
                return;
            }
            childColumns.Add(hwvDgvc);

            if (hwvDgvc.parent != this)
            {
                hwvDgvc.parent = this;
            }
        }
示例#18
0
        private TreeNode InitTreeNode(DataGridViewColumnNode treeColumn)
        {
            if (treeColumn == null)
            {
                treeColumn = new DataGridViewColumnNode();
            }
            DataGridViewColumnNode rootDgvcColumn = treeColumn.Clone();

            TreeNode tnRoot = new TreeNode();

            tnRoot.Text = "树形表头";
            tnRoot.Tag  = rootDgvcColumn;

            SubInitTreeNode(treeColumn, ref tnRoot);

            return(tnRoot);
        }
示例#19
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            object selectedObject;

            if (e.Node.Parent == null)
            {
                selectedObject = null;
            }
            else
            {
                DataGridViewColumnNode hwvDgvc = e.Node.Tag as DataGridViewColumnNode;
                selectedObject = hwvDgvc;
            }
            SetSelectedObject(selectedObject);

            SetButtonEnabled(e.Node);
        }
示例#20
0
        //弹出时机
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                //MyCustomTypeDescriptor<HWVPropertyAttribute> myctD = context.Instance as MyCustomTypeDescriptor<HWVPropertyAttribute>;
                //IPageOwner PageOwner = myctD.SelectObject as IPageOwner;
                DataGridViewColumnNode dgvc = value as DataGridViewColumnNode;

                FrmTreeHeadColumnsEdit fciqe = new FrmTreeHeadColumnsEdit(dgvc);
                fciqe.StartPosition = FormStartPosition.CenterScreen;
                if (fciqe.ShowDialog() == DialogResult.OK)
                {
                    value = fciqe.RootColumn;
                    return(value);
                }
            }
            return(base.EditValue(context, provider, value));
        }
示例#21
0
        private void SubInitTreeNode(DataGridViewColumnNode dgvcParent, ref TreeNode tnParent)
        {
            for (int i = 0; i < dgvcParent.ChildColumns.Count; i++)
            {
                DataGridViewColumnNode dgvc = dgvcParent.ChildColumns[i];

                DataGridViewColumnNode dgvcCopy = dgvc.Clone();
                TreeNode tn = new TreeNode();
                tn.Text = dgvcCopy.Text;
                tn.Tag  = dgvcCopy;
                tnParent.Nodes.Add(tn);

                if (dgvc.IsLeafColumn)
                {
                    continue;
                }

                SubInitTreeNode(dgvc, ref tn);
            }
        }
        int getDepth(DataGridViewColumnNode dgvc)
        {
            int max = 0;

            if (dgvc.childColumns == null || dgvc.childColumns.Count == 0)
            {
                return(0);
            }
            else
            {
                for (int i = 0; i < dgvc.childColumns.Count; i++)
                {
                    DataGridViewColumnNode item = dgvc.ChildColumns[i];
                    if (getDepth(item) > max)
                    {
                        max = getDepth(item);
                    }
                }
                return(max + 1);
            }
        }
示例#23
0
        private void DrawCell(DataGridViewColumnNode node, DataGridViewCellPaintingEventArgs e, Rectangle uhRectangle)
        {
            //Color clr = this.Columns[e.ColumnIndex].HeaderCell.Style.BackColor;
            ////DataGridView1.Columns[0].HeaderCell.Style.BackColor = Color.Blue;
            //if (e.CellStyle.BackColor == this.ColumnHeadersDefaultCellStyle.BackColor)
            //{
            //}

            //DataGridView1.ColumnHeadersDefaultCellStyle.BackColor
            SolidBrush backColorBrush = new SolidBrush(e.CellStyle.BackColor);

            //if (e.ColumnIndex == 2)
            //    backColorBrush = new SolidBrush(Color.Pink);
            //SolidBrush backColorBrush = new SolidBrush(clr);
            // 画矩形
            e.Graphics.FillRectangle(backColorBrush, uhRectangle);
            //画边框
            e.Graphics.DrawRectangle(gridLinePen, uhRectangle);

            string[] Ctext;//存放分组字符串
            if (node.Text.Contains(","))
            {
                Ctext = node.Text.Split(new char[] { ',' });
                int zhs = Ctext.Length;//字符串要显示的总行数
                for (int i = 0; i < zhs; i++)
                {
                    SizeF sf = e.Graphics.MeasureString(Ctext[i], this.Font);
                    e.Graphics.DrawString(Ctext[i], this.Font, new SolidBrush(e.CellStyle.ForeColor)
                                          , uhRectangle.Left + uhRectangle.Width / 2 - 1.0f * sf.Width / 2 + 2
                                          , uhRectangle.Top + uhRectangle.Height / 2 - 1.0f * sf.Height * zhs / 2 + 1.0f * sf.Height * i + 2);
                }
            }
            else
            {
                SizeF sf = e.Graphics.MeasureString(node.Text, this.Font);
                e.Graphics.DrawString(node.Text, this.Font, new SolidBrush(e.CellStyle.ForeColor)
                                      , uhRectangle.Left + uhRectangle.Width / 2 - 1.0f * sf.Width / 2 + 2
                                      , uhRectangle.Top + uhRectangle.Height / 2 - 1.0f * sf.Height / 2 + 2);
            }
        }
示例#24
0
        ///<summary>
        ///绘制合并表头--绘制表头思路改进
        ///</summary>
        ///<param name="node">合并表头节点</param>
        ///<param name="e">绘图参数集</param>
        ///<param name="level">结点深度</param>
        ///<remarks></remarks>
        private void PaintUnitHeader(DataGridViewColumnNode node, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
        {
            bool columnVisible = this.Columns[e.ColumnIndex].Visible;

            Rectangle  uhRectangle;
            SolidBrush backColorBrush = new SolidBrush(e.CellStyle.BackColor);

            int fakeLevel = node.FakeLevel;

            if (node.ChildColumns.Count == 0)
            {
                if (e.ColumnIndex == 1)
                {
                }
                if (e.ColumnIndex == 2)
                {
                }

                #region 叶子

                //此列没有子列,且是顶级列
                if (fakeLevel == 0)
                {
                    uhRectangle = new Rectangle(e.CellBounds.Left - 1,
                                                e.CellBounds.Top + fakeLevel * realHeadCellHeight - 1,
                                                e.CellBounds.Width,
                                                this.ColumnHeadersHeight);
                }
                //此列是最后一列
                else if (fakeLevel == columnDeep - 1)
                {
                    uhRectangle = new Rectangle(e.CellBounds.Left - 1,
                                                e.CellBounds.Top + fakeLevel * realHeadCellHeight - 1,
                                                e.CellBounds.Width,
                                                this.ColumnHeadersHeight - realHeadCellHeight * (columnDeep - 1));
                }
                //其它情况
                else
                {
                    uhRectangle = new Rectangle(e.CellBounds.Left - 1,
                                                e.CellBounds.Top + fakeLevel * realHeadCellHeight - 1,
                                                e.CellBounds.Width,
                                                realHeadCellHeight * (columnDeep - fakeLevel));
                }

                if (e.ColumnIndex == 2)
                {
                }

                DrawCell(node, e, uhRectangle);

                #endregion
            }
            else
            {
                #region 非叶子

                //取得最左叶子节点
                DataGridViewColumnNode newtreenode1 = node;
                while (newtreenode1.FristColumn != null)
                {
                    newtreenode1 = newtreenode1.FristColumn;
                }
                //取得最左叶子节点列号
                int leftindex = GetColumnListNodeIndex(newtreenode1);

                //计算要减去的距离
                int leftrangge = 0;

                for (int i = leftindex; i < e.ColumnIndex; i++)
                {
                    leftrangge += this.Columns[i].Width;
                }

                //int visibleColumnsCount = GetVisibleColumnsCount();
                //得到给节点对应的宽度
                int nodewidth = GetUnitHeaderWidth(node);
                //得到矩形区域
                uhRectangle = new Rectangle(e.CellBounds.Left - leftrangge - 1,
                                            e.CellBounds.Top + fakeLevel * realHeadCellHeight,
                                            nodewidth,
                                            realHeadCellHeight);

                DrawCell(node, e, uhRectangle);

                #endregion
            }

            #region 递归

            //递归调用 使得每列触发该列上所有节点的重绘
            if (node.Parent != null)
            {
                PaintUnitHeader(node.Parent, e);
            }

            #endregion
        }
示例#25
0
 public void SetTreeHeadRootColumn(DataGridViewColumnNode TreeHeadRootColumn)
 {
     this.treeHeadRootColumn = TreeHeadRootColumn;
     this.InitTreeHeadRootColumn();
 }
示例#26
0
        public DataGridViewColumnNode GetParent(int levelIndex)
        {
            DataGridViewColumnNode dgvcn = treeHeadRootColumn.GetParent(levelIndex);

            return(dgvcn);
        }
示例#27
0
 private void btnSure_Click(object sender, EventArgs e)
 {
     rootColumn        = GetHWVDataGridViewColumn();
     this.DialogResult = DialogResult.OK;
 }