Winform 中DataGridView控件添加行标题
有很多种方法。
1、可以在DataGridView控件中的RowStateChanged事件改变行标题单元格的值(Row.HeaderCell.Value)
/// <summary>
/// 行状态更改时发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
//e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
e.Row.HeaderCell.Value = (e.Row.Index + ).ToString();//添加行号
}
2、可以在DataGridView控件中的RowPostPaint事件例进行设置,TextRenderer类的DrawText()方法使用指定的设备上下文、字体、颜色和格式说明在指定界限中绘制指定文本。
/// <summary>
/// 所有单元格绘制后,执行 行绘制时发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//
System.Drawing.Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Y, this.dataGridView1.RowHeadersWidth - , this.dataGridView1.ColumnHeadersHeight);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + ).ToString(), this.dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);//”TextFormatFlags.VerticalCenter | TextFormatFlags.Right“中“|”有增加的作用,此处添加了两种文本字符格式样式
}
dev 的DevExpress.XtraGrid.Views.Grid.GridView控件添加行号:
/// <summary>
/// GridView 显示行号 设置行号列的宽度
/// </summary>
/// <param name="gv">GridView 控件名称</param>
/// <param name="width">行号列的宽度 如果为null或为0 默认为30</param>
public void DrawRowIndicator(DevExpress.XtraGrid.Views.Grid.GridView gv, int width)
{
gv.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gv_CustomDrawRowIndicator);
//if (width != null)
//{
if (width != )
{
gv.IndicatorWidth = width;
}
else
{
gv.IndicatorWidth = ;
}
//}
//else
//{
// gv.IndicatorWidth = 30;
//}
}
/// <summary>
/// 行号设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gv_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle > -)
{
e.Info.DisplayText = (e.RowHandle + ).ToString();
}
}
Winform 中DataGridView控件添加行标题的更多相关文章
- Winform中 DataGridView控件中的 CheckBox 的值读出来 始终 为 False ,已解决
private void DGV_DetailsViewer_CellContentClick(object sender, DataGridViewCellEventArgs e) { )) { D ...
- Winform中checklistbox控件的常用方法
Winform中checklistbox控件的常用方法最近用到checklistbox控件,在使用其过程中,收集了其相关的代码段1.添加项checkedListBox1.Items.Add(" ...
- 为 DataGridView 控件添加行号
虽然好像不经常用到,不过还是记下来防止以后用到 /// <summary> /// 为 DataGridView 控件添加行号 /// </summary> /// <p ...
- [C#]WinForm 中 comboBox控件之数据绑定
[C#]WinForm 中 comboBox控件之数据绑定 一.IList 现在我们直接创建一个List集合,然后绑定 IList<string> list = new List<s ...
- Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼
Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼标签: winform treeview drawnode Treeview控 ...
- Winform 中DataGridView、dev Gridview控件添加行标题
有很多种方法. 1.可以在DataGridView控件中的RowStateChanged事件改变行标题单元格的值(Row.HeaderCell.Value) /// <summary> / ...
- Winform DataGridView控件添加行号
有很多种方法,这里介绍三种: A: 控件的RowStateChanged事件中添加,RowStateChanged事件是在行的状态更改(例如,失去或获得输入焦点)时发生的事件: e.Row.Hea ...
- 基于Winform框架DataGridView控件的SqlServer数据库查询展示功能的实现
关键词:Winform.DataGridView.SqlServer 一个基于winform框架的C/S软件,主要实现对SqlServer数据库数据表的实时查询. 一.为DataGridView添加数 ...
- C#中DataGridView控件使用大全
DataGridView 动态添加新行: DataGridView控件在实际应用中非常实用,特别需要表格显示数据时.可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行.假如需要动 ...
随机推荐
- Rails :布局和视图渲染
原文地址: http://guides.ruby-china.org/layouts_and_rendering.html Rails 布局和视图渲染 本文介绍 Action Controller 和 ...
- git常用命令 (阿里云code)
命令行指令 Git 全局设置 git config --global user.name "马会东" git config --global user.email "ma ...
- oracle中的日期:周月季年,首天未天。
SQL> SQL 前一小时数 FROM dual; 现在时间 当前小时数 前一小时数 ------------------- ---------- ---------- :: SQL> S ...
- 【巩固】Bootstrap笔记三
这段笔记介绍了bootstrp中以下几点应用点: 警告框的使用 面板功能 运用chart.js制作图表 进度条的制作 媒体对象的制作 有一个元素如果有属性alert-dismissible" ...
- 小例子 熟悉jquery
<div class="tab-head"> <h2 id="tab1" class="selected">JQGr ...
- Netty服务端与客户端(源码一)
首先,整理NIO进行服务端开发的步骤: (1)创建ServerSocketChannel,配置它为非阻塞模式. (2)绑定监听,配置TCP参数,backlog的大小. (3)创建一个独立的I/O线程, ...
- Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...
- Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体旋转)
Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...
- logcat--目录
代码实现获取log日志和logcat使用方法:http://www.apkbus.com/android-128263-1-1.html logcat命令使用方法和查看android系统日志缓冲区内容 ...
- mount不是很熟悉 转载文章了解下 转自http://forum.ubuntu.org.cn/viewtopic.php?f=120&t=257333
纯粹针对刚刚解封开包的新新手,老鸟们请自觉绕行,否则浪费你的时间你非要逼我做谋杀犯可不光我的事你还没地方说理去.如果你正好是个崭新的新手,就耐心的花点时间看看吧,至少大概看看,不要在一个陌生又黑暗的到 ...