01

WinForm中datagridview增加行号

在界面上拖一个控件dataGridView1,在datagridview添加行事件中添加如下代码:

private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
this.dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
}
catch
{
MessageBox.Show("处理异常:表格行标题添加异常");
}
}

  

这样表格中每次有新行增添就会被自动打标行号.

02

WPF中datagrid增加行号

WPF类似WinForm中datagridview的表格控件是datagrid,我们可以将行标题添加代码写在LoadingRow事件中:

①附件事件:

一般是在xmal窗体的cs初始化类中:

DG.LoadingRow += new EventHandler<DataGridRowEventArgs>(DG_LoadingRow);

  CM框架mvvm模式下:

[Event LoadingRow]=[DG_LoadingRow($source,$eventArgs)]"

  DG_LoadingRow事件如下:

private void DG_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}

  

03

WPF dev控件GridControl增加行号

dev控件GridControl没有行增添增添事件,我们可以用下面的方法去做:

增加控件引用空间

xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"

  

<dxg:GridControl Name="grid" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView RowIndicatorContentTemplate="{StaticResource rowIndicatorContentTemplate}"/>
</dxg:GridControl.View>
</dxg:GridControl

  定义模板资源

<UserControl.Resources>
<DataTemplate x:Key="rowIndicatorContentTemplate">
<StackPanel VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Path=RowHandle.Value}"
TextAlignment="Center"
Foreground="Gray"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>

  

----------------------------------------------------

以上就是本节的全部内容,如果感觉有用,请多多的点击在看和分享,需要进技术交流群的,请加小编微信zls20210502,切记备注 进群

C# datagridview、datagrid、GridControl增加行号的更多相关文章

  1. jquery plugins —— datatables 增加行号

    table = $("#Table").DataTable({ "rowCallback": function (row, data, dataIndex) { ...

  2. 【原】Infragistics.Win.UltraWinGrid.UltraGrid 增加行号

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayo ...

  3. MySQL增加行号rownum

    select * from ( select @rownum:=@rownum+1 AS rownum, app_t.* from ( select * from app_custom where 1 ...

  4. poi读取Excel模板并修改模板内容与动态的增加行

    有时候我们可能遇到相当复杂的excel,比如表头的合并等操作,一种简单的方式就是直接代码合并(浪费时间),另一种就是写好模板,动态的向模板中增加行和修改指定单元格数据. 1.一个简单的根据模板shee ...

  5. pandas删除行删除列,增加行增加列

    创建df: >>> df = pd.DataFrame(np.arange(16).reshape(4, 4), columns=list('ABCD'), index=list(' ...

  6. .net+EF+mvc通过EasyUI的DataGrid实现增删改查

    @{    Layout = null;} <!DOCTYPE html> <html><head>    <meta name="viewport ...

  7. vim 加行号 和取消行号

    :set nu #是加行号 :set nonu #是去掉行号

  8. WPF DataGrid 自动生成行号的方法(通过修改RowHeaderTemplate的方式)

    WPF中的DataGrid自动生成行号的方法有很多,这里记录了一种通过修改 RowHeaderTemplate的方式来生成行号: 方法一: xaml界面: <Window ... xmlns:l ...

  9. DataGridView大扩展——显示行号

    原文 DataGridView大扩展——显示行号 在DataGridView 的实际使用中,经常需要标示出行号,这样可以比较醒目地看到当前信息.不过DataGridView 在绘制 DataGridV ...

随机推荐

  1. Google Chrome浏览器必备的20个插件

    Google Chrome浏览器虽然与火狐浏览器有所区别,不过他们都是很开放的浏览器产品,所以也有许多有用的插件,这些插件对于日常生活与网络冲浪都很有用,比如网银,炒股等. Google Chrome ...

  2. freemodbus移植、实例及其测试方法

    Modbus简介 参考:Modbus​协议​深入​讲解 https://www.ni.com/zh-cn/innovations/white-papers/14/the-modbus-protocol ...

  3. AI:用软件逻辑做硬件爆款

    "我们的野心不止那么一点点." 百度集团副总裁.百度智能生活事业群组(SLG)总经理.小度CEO景鲲曾多次对外表达过这样的观点. 在2021年百度世界大会上,小度又一口气发布了四款 ...

  4. oracle table()函数

    PL/SQL表---table()函数用法/* PL/SQL表---table()函数用法:利用table()函数,我们可以将PL/SQL返回的结果集代替table. oracle内存表在查询和报表的 ...

  5. CodeForce-801C Voltage Keepsake(二分)

    题目大意:有n个装备,每个设备耗能为每单位时间耗能ai,初始能量为bi;你有一个充电宝,每单位时间可以冲p能量,你可以在任意时间任意拔冲. 如果可以所有设备都可以一直工作下去,输出-1:否则,输出所有 ...

  6. Django学习day15BBS项目开发4.0(完结)

    每日测验 """ 今日考题: 1.简述自定义标签,过滤器,inclusion_tag的方法,并简要说一说三者的特点及响应流程 2.简述个人侧边栏展示及筛选业务逻辑 3.简 ...

  7. Hyper-V + WSL2与 VirtualBox 共存

    Hyper-V + WSL2与 VirtualBox 共存 这样的教程网上有很多,我先简单复述一下.真正麻烦的是我遇到的问题--开启 Hyper-V 后我的电脑会多出几个删不掉的虚拟显示器来,会在文章 ...

  8. Rust之旅 02.通过例子学习自定义类型

    本期文章接上期继续讲述Rust语言中的数据类型,Rust自定义数据类型主要是通过下面这两个关键字来创建: 结构体( struct ): 定义一个结构体(structure) 枚举( enum ): 定 ...

  9. nginx使用用户真实IP做hash(解决经过CND后ip_hash失效问题)

    在nginx中常用的有以下四种负载均衡的算法,分别是:round-robin.ip-hash.least-connected和weighted.当然在实际生产中或许使用最多的就是ip-hash了,一般 ...

  10. Java基础系列(5)- 使用IDEA开发

    IDEA开发 下载安装IDEA https://www.cnblogs.com/gltou/p/14956060.html 使用IDEA编写helloworld 踩坑总结 run的时候提示" ...