Winform中datagridview控件使用

使用dataGridView控件常遇到的問題就是如何繪製行號,記錄在下以方便日後查看

//繪製表格行號
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
     DataGridView dataGridView = (DataGridView)sender;
     SolidBrush b = new SolidBrush(dataGridView.RowHeadersDefaultCellStyle.ForeColor);
     e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 6);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章