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. 快速使用 Docker 上手 Sentry-CLI - 玩转 Source Maps 使用 (create-react-app)

    系列 快速使用 Docker 上手 Sentry-CLI - 创建版本 入门 使用 sentry-cli 上传 source maps 时,您需要设置构建系统以创建版本(release)并上传与该版本 ...

  2. JavaScript高级程序设计读书笔记之JSON

    JSON(JavaScript Object Notation)JavaScript对象表示法.JSON是JavaScript的一个严格的子集,利用了JavaScript中的一些模式来表示结构化数据. ...

  3. vue 上传头像悬浮显示文字

    template部分: 头像外部加一个 div <div class="user-info-head"> </div>   css 部分 <style ...

  4. openswan IPSec专栏目录锦集

    为了方便查阅现有的文章,特准备一个目录页供后续查询使用 专栏序言 1. 基础知识 openswan任务调度基础知识之信号 2. openswan环境搭建 openswan框架和编译时说明 opensw ...

  5. openswan协商流程之(五):main_inR2_outI3()

    主模式第五包:main_inR2_outI3 文章目录 主模式第五包:main_inR2_outI3 1. 序言 2.函数调用关系 3. 第五个报文流程图 4. main_inR2_outI3()源码 ...

  6. 【HMS Core 6.0全球上线】Toolkit,您的智能辅助编程好帮手

    HMS Core 6.0已于7月15日全球上线.本次版本中,华为HMS Toolkit向广大开发者推出了智能辅助编程助手SmartCoder,帮助开发者轻松高效地集成HMS Core,开发新功能,创建 ...

  7. Java链表练习题小结

    链表 链表(Linked List)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer).一个链表节点至少包含一个 数据域和 ...

  8. Spring Boot中使用@Async实现异步调用,加速任务的执行!

    什么是"异步调用"?"异步调用"对应的是"同步调用",同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执行 ...

  9. study day2

    study day2 windows 常用快捷键 CTRL C:复制 CTRL V:粘贴 CTRL A:全选 CTRL X:剪切 CTRL S:保存 CTRL Z:撤销 alt f4:关闭窗口 shi ...

  10. Insecure CAPTCHA (不安全的验证码)

    dvwa不能正常显示,需要在配置文件中加入谷歌的密钥: $_DVWA[ 'recaptcha_public_key' ] = '6LfX8tQUAAAAAOqhpvS7-b4RQ_9GVQIh48dR ...