zoukankan
html css js c++ java
可以显示行号的DataGrid(WinForm)
关键字:WinForm DataGrid 显示行号
近日在网上搜到一些如何在WinForm的DataGrid上显示行号的资料,因此自己也写了一段代码,因为是在前人实践的基础上做了些修改,所以不敢独享。如下:
/**/
///
<summary>
///
可以显示行号的DataGrid
///
</summary>
public
class
HDataGrid : System.Windows.Forms.DataGrid
{
public
HDataGrid():
base
()
{}
private
bool
_DisplayRowNumber
=
false
;
/**/
///
<summary>
///
控制是否显示行号
///
</summary>
[Browsable(
true
),DefaultValue(
false
),Description(
"
是否显示行号
"
)]
public
bool
DisplayRowNumber
{
get
{
return
_DisplayRowNumber; }
set
{
_DisplayRowNumber
=
value;
this
.Invalidate();
}
}
/**/
///
<summary>
///
重载OnPaint方法显示行号
///
</summary>
///
<param name="e"></param>
protected
override
void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base
.OnPaint (e);
//
显示行号
if
(DisplayRowNumber
&&
this
.RowHeadersVisible
&&
this
.VisibleColumnCount
>
0
)
{
if
(
this
.DataSource
==
null
)
return
;
int
iRowNumStart
=
this
.VertScrollBar.Value;
int
yPos
=
0
;
int
iRowNumEnd
=
iRowNumStart
+
this
.VisibleRowCount;
while
(iRowNumStart
<
iRowNumEnd)
{
yPos
=
this
.GetCellBounds(iRowNumStart
++
,
0
).Y
+
2
;
string
strRowNum
=
string
.Format(
"
{0}
"
,iRowNumStart);
e.Graphics.DrawString(strRowNum,
this
.Font ,
new
System.Drawing.SolidBrush(System.Drawing.Color.Black),
6
, yPos);
}
}
}
}
查看全文
相关阅读:
[BZOJ1385][Baltic2000]Division expression
[BZOJ1412/Luogu2598][ZJOI2009]狼和羊的故事
iPhone SlideShow
替换一个文件中的内容BAT
用指定字符串替换指定内容
修改注册表
如何在单独的窗口中打开 Excel 文件
IBatis和Hibernate区别
c# 常用的面试题
在线编译器
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
图的广度优先遍历
贪心算法
ACM刷题之路(十四)逆元取模 Travel along the Line
ACM刷题之路(十三)数据结构——链表
ACM刷题之路(十二)数据结构——顺序表
ACM刷题之路(十一)堆、栈、队列实现表达式转换
ACM刷题之路(十)博弈论 jack & rose
ACM刷题之路(九)数论-逆序组 交换座位
ACM刷题之路(八)数论-取余 停车位划分
ACM刷题之路(七)字符串处理 记元培ACM院赛
热门文章
ACM刷题之路(六)直线相交问题 POJ3304 Segments
ACM刷题之路(五)最短路 Dijkstra POJ2387
[数论]高斯消元学习笔记
[快速变换专题][FFT/NTT/MTT/FWT/分治FFT]Duliu多项式学习笔记
[BZOJ2456/ZOJ2132]mode/The Most Frequent Number
[BZOJ1724][Usaco2006 Nov]Fence Repair 切割木板
[BZOJ1263/Luogu4157][SCOI2006]整数划分
[BZOJ1221/Luogu2223][HNOI2001]软件开发
[BZOJ2424/Luogu2517][HAOI2010]订货
[BZOJ3171/Luogu3965][TJOI2013]循环格
Copyright © 2011-2022 走看看