windowsforms-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-3220e6ee.md
Gets the column’s data type.
Namespace : DevExpress.XtraGrid.Columns
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[Browsable(false)]
public virtual Type ColumnType { get; }
<Browsable(False)>
Public Overridable ReadOnly Property ColumnType As Type
| Type | Description |
|---|---|
| Type |
A System.Type value representing column data type.
|
The code sample below illustrates how to highlight all DateTime columns in a grid.
gridView1.CustomDrawCell += GridView1_CustomDrawCell;
private void GridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
GridView view = sender as GridView;
if (column.ColumnType == typeof(DateTime))
{
e.Cache.FillRectangle(Color.Salmon, e.Bounds);
e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);
e.Handled = true;
}
}
Private gridView1.CustomDrawCell += AddressOf GridView1_CustomDrawCell
Private Sub GridView1_CustomDrawCell(ByVal sender As Object, ByVal e As RowCellCustomDrawEventArgs)
Dim view As GridView = TryCast(sender, GridView)
If column.ColumnType Is GetType(Date) Then
e.Cache.FillRectangle(Color.Salmon, e.Bounds)
e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds)
e.Handled = True
End If
End Sub
Note
Columns return valid ColumnType property values only after a Grid is completely initialized. Call the GridControl.ForceInitialize() method to ensure you do not read the ColumnType property too early.
The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnType property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-grid-introduce-custom-options-in-auto-filter-row/CS/WindowsApplication3/CustomGrid.cs#L38
{
if (column.ColumnType == typeof(DateTime) && strVal.Length > 0)
{
winforms-reporting-create-grid-based-report/CS/ConvertGridToReportExample/Form1.cs#L56
foreach (GridColumn c in gridView.Columns)
dTable.Columns.Add(c.FieldName, c.ColumnType);
for (int r = 0; r < gridView.RowCount; r++)
winforms-grid-introduce-custom-options-in-auto-filter-row/VB/WindowsApplication3/CustomGrid.vb#L52
Protected Overrides Function CreateAutoFilterCriterion(ByVal column As DevExpress.XtraGrid.Columns.GridColumn, ByVal condition As DevExpress.XtraGrid.Columns.AutoFilterCondition, ByVal _value As Object, ByVal strVal As String) As DevExpress.Data.Filtering.CriteriaOperator
If column.ColumnType Is GetType(Date) AndAlso strVal.Length > 0 Then
Dim type As BinaryOperatorType = BinaryOperatorType.Equal
winforms-reporting-create-grid-based-report/VB/ConvertGridToReportExample/Form1.vb#L48
For Each c As GridColumn In gridView.Columns
dTable.Columns.Add(c.FieldName, c.ColumnType)
Next c
See Also