在实际项目中,有时表格需要绘制行号。
事件
RowPostPaint.
方法
使用指定的设备上下文、字体和颜色在指定界限中绘制指定文本。
public static void DrawText(IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test_DataGridView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//全局变量
int rowIndex;
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = Source();
}
//数据表资源
private DataTab