html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

DataGrid(WinForm)显示行号最简单的方法_.NET教程_编程技术

[ ] 已经帮助:人解决问题
datagrid|显示
同样是重载OnPaint 方法,但是方法应该是比较巧妙的!而且不用担心标题是不是有显示,也不用去计算坐标,很方便的说!


protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if(this.DataSource!=null)
{
if( this.VisibleRowCount == 0 )return;

Rectangle currRct;

int iRowCount = this.VisibleRowCount;

string sText = "";

int nowY = 0;

for( int i = 0 ; i < iRowCount ; i++ )
{
currRct = (Rectangle)this.GetCellBounds( i, 0 );
nowY = currRct.Y + 2;
sText = string.Format( " {0}", i+1 );
e.Graphics.DrawString( sText, this.Font, new SolidBrush(Color.Black), 10, nowY );
}

}
}



vaWHTML5中文学习网 - HTML5先行者学习网
vaWHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助