Winform 中DataGridView、dev Gridview控件添加行标题
有很多种方法。
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、dev Gridview控件添加行标题的更多相关文章
- Winform 中DataGridView控件添加行标题
有很多种方法. 1.可以在DataGridView控件中的RowStateChanged事件改变行标题单元格的值(Row.HeaderCell.Value) /// <summary> / ...
- WinForm中使用AnyCAD三维控件 の 初始化
在WinForm中可以方便的集成AnyCAD.Net三维控件,只需要以下几部即可完成. 一.添加DLL程序集 AnyCAD.Foundation.Net.dll AnyCAD.Presentation ...
- Winform带dataGridview的Combox控件
调用控件: public partial class Form1 : Form { public Form1() { InitializeComponent(); //---------------- ...
- winform中如何使用timer控件实现欢迎(初始加载)窗口
第一步.新建窗体项目命名为:TestWelcomeFrm,如下图: 第二步.在新项目中,增加欢迎窗口,命名为WelFrm,整个项目目录如下: 第三步.修改program.cs中启动代码如下: WelF ...
- 自动为DEV GridView控件添加SizeChanged事件
实现gdv设置的抽象对象,不用每个gdv控件都添加sizechanged事件,只需执行gdc绑定sql函数,在其中会自动添加SizeChanged事件. //2016.5.13 by sngk //根 ...
- winform中的时间轴控件
我现在做的项目遇到一个需求,就是有没有类似的控件: 我要实现的功能是:播放录像. 某个时间段内假如有2个录像,这个坐标表示的是时间,假如我现在拖动时间轴,拖到第一个录像里面开始播放第一个录像,拖到2个 ...
- c#winform中如何修改ListView控件每个单元格的颜色
ListView在View属性为Details的时候它呈现的方式和DataGirdView差不多,它的每一行都是一个ListViewItem,然而每个ListViewItem都有一个BackColor ...
- 【原创】WinForm中实现单独Time控件的方式
WinForm默认只提供了DateTimePicker,今天的项目只用时间,不能出现日期,百撕不得骑姐(^^),也没花多少时间,随便试了一下,就成功了,分享一下. 在DateTimePicker属性中 ...
- WinForm中使用自定义Tooltip控件
private ToolTip tooltipCtr; 构造函数中: 隐藏默认的Tooltip:this.ShowCellToolTips = false; this.tooltipCtr = new ...
随机推荐
- python读取 ini 配置文件
在详解python读取ini文件之前,我们先说明一个ini文件的组成: 一个ini文件是由多个section组成,每个section中以key=vlaue形式存储数据: 然后我们来使用python读取 ...
- ArcGIS 重新创建几何服务(GeometryService)
#参考官方网址:http://enterprise.arcgis.com/zh-cn/server/10.4/administer/windows/re-creating-the-geometry-s ...
- 关于C# 语言
C# 语法高度重视表达,但学习起来也很简单轻松. 任何熟悉 C.C++ 或 Java 的人都可以立即认出 C# 的大括号语法. 通常情况下,了解上述任何一种语言的开发者可以在很短的时间内就开始使用 C ...
- C#变量---xdd
cshape(c#)学习笔记 1. string str1=Console.ReadLine();//键盘输入的默认为字符串 2. Console.WriteLine('你的成绩是'+a+'分'); ...
- socket解决编码解码问题
MySocket类: import socket class MySocket(socket.socket): # 继承自socket文件中的socket类,此时socket就是父类 def __in ...
- Erlang/Elixir精选-第1期
第1期(20191202) 文章 A short guide to the structure and internals of the Erlang distributed messaging fa ...
- jenkins System error
背景 在使用WAR包安装jenkins后,启动tomcat,显示启动成功,但最后提示信息如下: 04-Dec-2018 03:28:21.563 WARNING [Computer.threadPoo ...
- Chapter 04—Basic Data Management
1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...
- swiper实现一个好看的轮播图
轮播是我们在编写页面中经常遇到的模块,所以网上也会有各种有有关轮播图的插件.今天忽然间看到了swiper上一个高颜值的轮播功能,顺便做一下分享. 首先页面在head内要先引用 swiper的css 和 ...
- 如何用 Python 写一个简易的抽奖程序
不知道有多少人是被这个头图骗进来的:) 事情的起因是这样的,上周有同学问小编,看着小编的示例代码敲代码,感觉自己也会写了,如果不看的话,七七八八可能也写的出来,但是一旦自己独立写一段程序,感觉到无从下 ...