- [DEVEXPRESS] Hỗ trợ tìm kiếm highlight không dấu và không khoảng cách trên Gridview Filter
 - [C#] Chia sẻ source code phần mềm Image Downloader tải hàng loạt hình ảnh từ danh sách link url
 - [C#] Chụp hình và quay video từ camera trên winform
 - [C#] Chia sẽ full source code tách file Pdf thành nhiều file với các tùy chọn
 - Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu và cảnh báo giá tăng giảm bằng C# và WPF
 - [VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam
 - [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
 - [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
 - Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
 - [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
 - [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
 - [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
 - [C#] Hướng dẫn tạo mã QRcode Style trên winform
 - [C#] Hướng dẫn sử dụng temp mail service api trên winform
 - [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
 - [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
 - [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
 - [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
 - [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
 - [C#] Hướng dẫn download file từ Minio Server Winform
 
[C#] Hướng dẫn tạo Auto Number trên Datagridview winform
Xin chào các bạn, bài viết hôm nay mình tiếp tục hướng dẫn các bạn cách đánh số thứ tự trên datagridview C#, Winform.
[C#] How to add auto number in datagridview winform
Dưới đây, là hình ảnh demo ứng dụng:

Các bạn, thấy ở dòng bên trái mình đã đánh số thự tự vào.
Source code C#:
using EmployeeDataExample;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AddNumberRowInDataGridView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.RowPostPaint += DataGridView1_RowPostPaint;
            dataGridView1.AutoGenerateColumns = false;
        }
        private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            //using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
            using (SolidBrush b = new SolidBrush(Color.Red))
            {                
                e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
            }
        }
        private async void Form1_Load(object sender, EventArgs e)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var data = await new EmployeeData().GetEmployeesAsync();
            dataGridView1.DataSource = data;
        }
    }
}
Các bạn, chỉ cần add sự kiện event: DataGridView1_RowPostPaint để vẽ số thứ tự.
Thanks for watching!


