zoukankan      html  css  js  c++  java
  • 为DataGridView添加行号

    1、首先为DataGridView添加一个RowPostPaint事件。

    2、在事件代码中把下面的代码贴上:


    private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
            {
                
    try
                {
                    
    //添加行号 
                    SolidBrush v_SolidBrush = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
                    
    int v_LineNo = 0;
                    v_LineNo 
    = e.RowIndex + 1;

                    
    string v_Line = v_LineNo.ToString();

                    e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X 
    + 15, e.RowBounds.Location.Y + 5);

                }
                
    catch (Exception ex)
                {
                    MessageBox.Show(
    "添加行号时发生错误,错误信息:" + ex.Message, "操作失败");
                }
            }
  • 相关阅读:
    2022 开年计划
    阿里云,华为云产品使用汇总
    git 连接gitlab
    golang 学习汇总
    mongodb分片集群的搭建总结
    2021 年终 总结,随想
    vue请求RSA加密
    sockjsnode/info请求失败
    rules校验
    [转]SPRINGBOOT启动流程及其原理
  • 原文地址:https://www.cnblogs.com/hantianwei/p/1571974.html
Copyright © 2011-2022 走看看