windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-e06c82e4.md
Enables you to specify content alignment for individual cells.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Appearance")]
public event RowCellAlignmentEventHandler RowCellDefaultAlignment
<DXCategory("Appearance")>
Public Event RowCellDefaultAlignment As RowCellAlignmentEventHandler
The RowCellDefaultAlignment event's data class is RowCellAlignmentEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CellValue | Returns the currently processed cell value. Inherited from CustomRowCellEventArgs. |
| Column | Gets the column to which the currently processed cell corresponds. Inherited from CustomRowCellEventArgs. |
| HorzAlignment | Gets or sets the cell content’s default horizontal alignment. |
| RowHandle | Gets the handle of the row that contains the processed cell. Inherited from CustomRowCellEventArgs. |
Cell values are automatically aligned with respect to their type, and the kind of editor used to modify them. This default behavior can be overridden by handling the RowCellDefaultAlignment event. Handling this event enables you to align values not only within columns, but within individual cells. Use the RowCellAlignmentEventArgs.HorzAlignment parameter to specify the required default horizontal alignment.
The event’s CustomRowCellEventArgs.Column and CustomRowCellEventArgs.RowHandle parameters allow you to identify the column and row that contain the processed cell.
Note that RowCellDefaultAlignment event handling is in effect for columns that have the AppearanceCell.TextOptions.HAlignment property set to HorzAlignment.Default.
The alignment specified by the RowCellDefaultAlignment event handler can be overridden by handling the GridView.RowCellStyle, GridView.CustomDrawCell and CardView.CustomDrawCardFieldValue events, or by setting a column’s AppearanceCell.TextOptions.HAlignment property.
The following sample code handles the ColumnView.RowCellDefaultAlignment event to specify the default horizontal alignment for cells whose row handle is either 4 or 5. Cells owned by the Category column are omitted.
The image below shows the Grid Control’s look and feel after sample code execution.
using DevExpress.XtraGrid.Views.Base;
private void gridView1_RowCellDefaultAlignment(object sender, RowCellAlignmentEventArgs e) {
if(e.Column.FieldName != "Category")
if(e.RowHandle == 4 || e.RowHandle == 5)
e.HorzAlignment = DevExpress.Utils.HorzAlignment.Far;
}
Imports DevExpress.XtraGrid.Views.Base
Private Sub GridView1_RowCellDefaultAlignment(ByVal sender As Object, _
ByVal e As RowCellAlignmentEventArgs) Handles GridView1.RowCellDefaultAlignment
If Not e.Column.FieldName Is "Category" Then
If e.RowHandle = 4 Or e.RowHandle = 5 Then
e.HorzAlignment = DevExpress.Utils.HorzAlignment.Far
End If
End If
End Sub
See Also