一 DEV控件下的 gridview单元格操作
/// <summary>
/// 在指定单元格里面画圆,写文字,修改外观(重绘数据时发生)/// </summary>
void gvBoardInfo_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (e.Column == gvBoardInfo.Columns["id"] && e.RowHandle > -1)
{
float x = e.Bounds.Location.X;
float y = e.Bounds.Location.Y;
e.Graphics.FillEllipse(Brushes.Red, x, y, 10, 10);
e.Graphics.DrawString(font, brush, x, y);
}
}
/// <summary>
/// 使单元格内容居中(重绘数据时发生)
/// </summary>
void gvBoardInfo_RowCellDefaultAlignment(object sender, DevExpress.XtraGrid.Views.Base.RowCellAlignmentEventArgs e)
{
e.HorzAlignment = HorzAlignment.Center;
}
/// <summary>
/// 修改指定单元格文字,背景等(重绘数据时发生)
/// </summary>
void gvBoardInfo_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
if (e.Column == gvBoardInfo.Columns["id"])
{
}
}
二 原生态 gridview 单元格操作
dgv.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//使内容居中
void
DGV_CellPainting(
object
sender, DataGridViewCellPaintingEventArgs e)
{
if
(e.RowIndex > -1 && e.ColumnIndex > -1)
{
e.PaintBackground(e.CellBounds,
false
);
e.Graphics.FillEllipse(Brushes.Red, e.CellBounds);
e.Graphics.DrawString(e.RowIndex.ToString() + e.ColumnIndex.ToString(),
this
.Font, Brushes.Black,
new
PointF(x,y));
e.Handled =
true
;
}}