Example of displaying row numbers in DataGridView control in C#Winform

This article demonstrates how to display row numbers for the DataGridView control in C# Winform.

First create a winform project, add a DataGridView control, and add two columns to the control.

Modify the CS code:

using System.Windows.Forms;

namespace DataGridviewDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //添加数据 可以直接在列中添加数据
            dataGridView1.Rows.Add("1","11");
            dataGridView1.Rows.Add("2", "22");
            dataGridView1.Rows.Add("3", "22");
            //防止行号多位时没有完全显示出来
            dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
        }
        //事件 行号显示在HeaderCell上
        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            /

Guess you like

Origin blog.csdn.net/qq_30725967/article/details/132268896
Recommended