DataGridView二维表头与合并单元格Word下载.docx

上传人:b****7 文档编号:22598592 上传时间:2023-02-04 格式:DOCX 页数:26 大小:111.32KB
下载 相关 举报
DataGridView二维表头与合并单元格Word下载.docx_第1页
第1页 / 共26页
DataGridView二维表头与合并单元格Word下载.docx_第2页
第2页 / 共26页
DataGridView二维表头与合并单元格Word下载.docx_第3页
第3页 / 共26页
DataGridView二维表头与合并单元格Word下载.docx_第4页
第4页 / 共26页
DataGridView二维表头与合并单元格Word下载.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

DataGridView二维表头与合并单元格Word下载.docx

《DataGridView二维表头与合并单元格Word下载.docx》由会员分享,可在线阅读,更多相关《DataGridView二维表头与合并单元格Word下载.docx(26页珍藏版)》请在冰豆网上搜索。

DataGridView二维表头与合并单元格Word下载.docx

privateArrayList_columnList=newArrayList();

privateint_cellHeight=17;

publicintCellHeight

get{return_cellHeight;

}

set{_cellHeight=value;

privateint_columnDeep=1;

privateboolHscrollRefresh=false;

///<

summary>

///水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误 

/summary>

[Description("

水平滚动时是否刷新表头,数据较多时可能会闪烁,不刷新时可能显示错误"

)]

publicboolRefreshAtHscroll

get{returnHscrollRefresh;

set{HscrollRefresh=value;

///构造函数

publicHeaderUnitView()

InitializeComponent();

this.ColumnHeadersHeightSizeMode=DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

//设置列高度显示模式 

publicHeaderUnitView(IContainercontainer)

container.Add(this);

设置或获得合并表头树的深度"

publicintColumnDeep

get

if(this.Columns.Count==0)

_columnDeep=1;

this.ColumnHeadersHeight=_cellHeight*_columnDeep;

return_columnDeep;

set

if(value<

1)

else

_columnDeep=value;

添加合并式单元格绘制的所需要的节点对象"

publicTreeView[]ColumnTreeView

get{return_columnTreeView;

if(_columnTreeView!

=null)

for(inti=0;

i<

=_columnTreeView.Length-1;

i++)

_columnTreeView[i].Dispose();

_columnTreeView=value;

设置添加的字段树的相关属性"

publicTreeViewColumnTreeViewNode

get{return_columnTreeView[0];

///设置或获取合并列的集合

[MergableProperty(false)]

[Editor("

System.Windows.Forms.Design.ListControlStringCollectionEditor,System.Design,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"

typeof(UITypeEditor))]

[DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)]

[Localizable(true)]

设置或获取合并列的集合"

),Browsable(true),Category("

单元格合并"

publicList<

string>

MergeColumnNames

return_mergecolumnname;

_mergecolumnname=value;

privateList<

_mergecolumnname=newList<

();

publicArrayListNadirColumnList

if(_columnTreeView==null)

returnnull;

if(_columnTreeView[0]==null)

if(_columnTreeView[0].Nodes==null)

if(_columnTreeView[0].Nodes.Count==0)

_columnList.Clear();

GetNadirColumnNodes(_columnList,_columnTreeView[0].Nodes[0],false);

return_columnList;

///<

///绘制合并表头 

paramname="

node"

>

合并表头节点<

/param>

e"

绘图参数集<

level"

结点深度<

remarks>

<

/remarks>

publicvoidPaintUnitHeader(

TreeNodenode,

System.Windows.Forms.DataGridViewCellPaintingEventArgse,

intlevel)

//根节点时退出递归调用 

if(level==0)

return;

RectangleFuhRectangle;

intuhWidth;

SolidBrushgridBrush=newSolidBrush(this.GridColor);

SolidBrushbackColorBrush=newSolidBrush(e.CellStyle.BackColor);

PengridLinePen=newPen(gridBrush);

StringFormattextFormat=newStringFormat();

textFormat.Alignment=StringAlignment.Center;

uhWidth=GetUnitHeaderWidth(node);

if(node.Nodes.Count==0)

uhRectangle=newRectangle(e.CellBounds.Left,

e.CellBounds.Top+node.Level*_cellHeight,

uhWidth-1,

_cellHeight*(_columnDeep-node.Level)-1);

uhRectangle=newRectangle(

e.CellBounds.Left,

_cellHeight-1);

//画矩形 

e.Graphics.FillRectangle(backColorBrush,uhRectangle);

//划底线 

e.Graphics.DrawLine(gridLinePen

uhRectangle.Left

uhRectangle.Bottom

uhRectangle.Right

uhRectangle.Bottom);

//划右端线 

uhRectangle.Top

////写字段文本 

e.Graphics.DrawString(node.Text,this.Font

newSolidBrush(e.CellStyle.ForeColor)

uhRectangle.Left+uhRectangle.Width/2-

e.Graphics.MeasureString(node.Text,this.Font).Width/2-1

uhRectangle.Top+

uhRectangle.Height/2-e.Graphics.MeasureString(node.Text,this.Font).Height/2);

//递归调用() 

if(node.PrevNode==null)

if(node.Parent!

PaintUnitHeader(node.Parent,e,level-1);

///获得合并标题字段的宽度 

字段节点<

returns>

字段宽度<

/returns>

privateintGetUnitHeaderWidth(TreeNodenode)

//获得非最底层字段的宽度 

intuhWidth=0;

//获得最底层字段的宽度 

if(node.Nodes==null)

returnthis.Columns[GetColumnListNodeIndex(node)].Width;

=node.Nodes.Count-1;

uhWidth=uhWidth+GetUnitHeaderWidth(node.Nodes[i]);

returnuhWidth;

///获得底层字段索引 

///'

<

底层字段节点<

索引<

privateintGetColumnListNodeIndex(TreeNodenode)

=_columnList.Count-1;

if(((TreeNode)_columnList[i]).Equals(node))

returni;

return-1;

///获得底层字段集合 

alList"

底层字段集合<

checked"

向上搜索与否<

privatevoidGetNadirColumnNodes(

ArrayListalList,

BooleanisChecked)

if(isChecked==false)

if(node.FirstNode==null)

alList.Add(node);

if(node.NextNode!

GetNadirColumnNodes(alList,node.NextNode,false);

GetNadirColumnNodes(alList,node.Parent,true);

if(node.FirstNode!

GetNadirColumnNodes(alList,node.FirstNode,false);

GetNadirColumnNodes(alList,node.NextNode,f

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1