一 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;}}
本文介绍了使用DEV控件下的GridView进行单元格自定义绘制的方法,包括如何在单元格内画圆、写文字及修改外观;同时展示了如何通过事件处理使单元格内容居中显示,以及如何修改指定单元格的文字和背景等属性。
638

被折叠的 条评论
为什么被折叠?



