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);
}
}
}
}
查看全文
相关阅读:
有序表查找
遍历二叉树
二叉树
[Oracle]使用InstantClient访问Oracle数据库
[部署]CentOS yum源
[部署]CentOS安装PHP环境
[部署]CentOS安装MariaDB
[部署]CentOS安装apache
Metrics.NET源码阅读笔记
[JavaScript]catch(ex)语句中的ex
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
php单一入口和多入口模式详细讲解
三个Linux权限
多选项表单
ACE.js自定义提示实现方法
移动端 Audio 不自动播放
[转] JavaScript生成GUID的算法
React问题汇总
[CSS碎片知识] 深入理解 vertical-align
[转] 29个你必须知道的Linux命令
[转]webpack 使用优化指南
热门文章
微信JSSDK与录音相关的坑
[转] 微信jssdk录音功能开发记录
React onPaste 获取粘贴板的值
图的存储结构
图的基本概念
散列表
多路查找树
平衡二叉树
二叉树查找
索引技术
Copyright © 2011-2022 走看看