windowsforms-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-8a02fd17.md
Gets or sets the in-place editor for all data cells that belong to this column.
Namespace : DevExpress.XtraGrid.Columns
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DefaultValue(null)]
[DXCategory("Data")]
public RepositoryItem ColumnEdit { get; set; }
<DXCategory("Data")>
<DefaultValue(Nothing)>
Public Property ColumnEdit As RepositoryItem
| Type | Default | Description |
|---|---|---|
| RepositoryItem | null |
A RepositoryItem descendant.
|
For information on how to provide in-place cell editors at design time, see the Modify and Validate Cell Values article.
If you set up the ColumnEdit property in code, do not forget to add any new RepositoryItems you create to the Data Grid’s EditorContainer.RepositoryItems collection. The following code illustrates how to assign a new ProgressBarControl in-place editor for the “Relevance” column. The editor’s KeyPress event is handled to allow users to tap\hold “+” and “-“ keys to edit cell values.
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors.Repository;
//create a repository item
RepositoryItemProgressBar ieProgress = new RepositoryItemProgressBar();
gridControl1.RepositoryItems.Add(ieProgress);
ieProgress.KeyPress += IeProgress_KeyPress;
//assign repository item
colRelevance.ColumnEdit = ieProgress;
//handle + and - keys press
private void IeProgress_KeyPress(object sender, KeyPressEventArgs e) {
int i = 0;
if (gridView1.ActiveEditor == null) return;
i = (int)gridView1.ActiveEditor.EditValue;
if (e.KeyChar == '+') {
if (i < 100)
gridView1.ActiveEditor.EditValue = i + 1;
}
if (e.KeyChar == '-') {
if (i > 0)
gridView1.ActiveEditor.EditValue = i - 1;
}
}
Imports System
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors.Repository
'create a repository item
Private ieProgress As New RepositoryItemProgressBar()
gridControl1.RepositoryItems.Add(ieProgress)
AddHandler ieProgress.KeyPress, AddressOf IeProgress_KeyPress
'assign repository item
colRelevance.ColumnEdit = ieProgress
'handle + and - keys press
private void IeProgress_KeyPress(Object sender, KeyPressEventArgs e)
Dim i As Integer = 0
If gridView1.ActiveEditor Is Nothing Then
Return
End If
i = CInt(Math.Truncate(gridView1.ActiveEditor.EditValue))
If e.KeyChar = "+"c Then
If i < 100 Then
gridView1.ActiveEditor.EditValue = i + 1
End If
End If
If e.KeyChar = "-"c Then
If i > 0 Then
gridView1.ActiveEditor.EditValue = i - 1
End If
End If
Along with the ColumnEdit property there are other ways to provide in-place editors to data cells.
|
API
|
Description
| | --- | --- | |
|
Identical to the ColumnEdit property but accepts editor names instead.
| |
|
Allows you to assign in-place editors to individual cells rather to the entire Grid column.
| |
GridView.CustomRowCellEditForEditing
|
Provides in-place editors that cells use only when a user starts editing cell values.
| |
|
If you did not assign a custom editor to a column, Data Grid automatically creates in-place editors for columns. The actual editor type depends on the bound field’s data type (for instance, a column bound to a DateTime data displays the DateEdit editor). The RealColumnEdit property allows you to retrieve this default column editor.
|
This example binds a GridControl to a collection of custom Record objects and demonstrates the following features:
Assigning an inplace editor (combo box) to a column
Specifying a column’s display name and data format by applying DataAnnotation attributes to Record class properties
Two ways of changing cell values - at the data source and grid level.
Highlighting cell values that meet a condition
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GridBoundToRuntimeCreatedData {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
gridControl1.DataSource = DataHelper.GetData(10);
// The grid automatically creates columns for the public fields found in the data source.
// Calling the gridView1.PopulateColumns method is not required unless the gridView1.OptionsBehavior.AutoPopulateColumns is disabled
// Create a ComboBox editor that shows available companies in the Company column
RepositoryItemComboBox riComboBox = new RepositoryItemComboBox();
riComboBox.Items.AddRange(DataHelper.companies);
gridControl1.RepositoryItems.Add(riComboBox);
gridView1.Columns["CompanyName"].ColumnEdit = riComboBox;
// Specify a different null value text presentation for the Image column
gridView1.Columns["Image"].RealColumnEdit.NullText = "[load image]";
//Highlight the RequiredDate cells that match a certain condition.
GridFormatRule gridFormatRule = new GridFormatRule();
FormatConditionRuleValue formatConditionRuleValue = new FormatConditionRuleValue();
gridFormatRule.Column = gridView1.Columns["RequiredDate"];
formatConditionRuleValue.PredefinedName = "Red Bold Text";
formatConditionRuleValue.Condition = FormatCondition.Greater;
formatConditionRuleValue.Value1 = DateTime.Today;
gridFormatRule.Rule = formatConditionRuleValue;
gridFormatRule.ApplyToRow = false;
gridView1.FormatRules.Add(gridFormatRule);
gridView1.BestFitColumns();
}
private void btnClearPayment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
//Change a cell value at the data source level to see the INotifyPropertyChanged interface in action.
gridView1.CloseEditor();
Record rec = gridView1.GetFocusedRow() as Record;
if (rec == null) return;
rec.Value = 0;
}
private void btnSetPayment_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
//Change a cell value at the grid level
gridView1.SetFocusedRowCellValue("Value", 999);
}
}
public class Record : INotifyPropertyChanged {
public Record() {
}
int id;
public int ID {
get { return id; }
set {
if (id != value) {
id = value;
OnPropertyChanged();
}
}
}
string text;
[DisplayName("Company")]
public string CompanyName {
get { return text; }
set {
if (text != value) {
if (string.IsNullOrEmpty(value))
throw new Exception();
text = value;
OnPropertyChanged();
}
}
}
Nullable<decimal> val;
[DataType(DataType.Currency)]
[DisplayName("Payment")]
public Nullable<decimal> Value {
get { return val; }
set {
if (val != value) {
val = value;
OnPropertyChanged();
}
}
}
DateTime dt;
[DisplayFormat(DataFormatString = "d")]
public DateTime RequiredDate {
get { return dt; }
set {
if (dt != value) {
dt = value;
OnPropertyChanged();
}
}
}
bool state;
public bool Processed {
get { return state; }
set {
if (state != value) {
state = value;
OnPropertyChanged();
}
}
}
Image image;
public Image Image {
get { return image; }
set {
if (image != value) {
image = value;
OnPropertyChanged();
}
}
}
public override string ToString() {
return string.Format("ID = {0}, Text = {1}", ID, CompanyName);
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "") {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class DataHelper {
public static string[] companies = new string[] { "Hanari Carnes", "Que Delícia", "Romero y tomillo", "Mère Paillarde",
"Comércio Mineiro", "Reggiani Caseifici", "Maison Dewey" };
public static Image[] images = new Image[] {
global::GridBoundToRuntimeCreatedData.Properties.Resources.palette_16x16,
global::GridBoundToRuntimeCreatedData.Properties.Resources.viewonweb_16x16,
global::GridBoundToRuntimeCreatedData.Properties.Resources.design_16x16,
global::GridBoundToRuntimeCreatedData.Properties.Resources.piestylepie_16x16,
global::GridBoundToRuntimeCreatedData.Properties.Resources.alignhorizontaltop2_16x16,
null
};
public static BindingList<Record> GetData(int count) {
BindingList<Record> records = new BindingList<Record>();
Random rnd = new Random();
for (int i = 0; i < count; i++) {
int n = rnd.Next(10);
records.Add(new Record() {
ID = i + 100,
CompanyName = companies[i % companies.Length],
RequiredDate = DateTime.Today.AddDays(n - 5),
Value = i % 2 == 0 ? (i + 1) * 123 : i * 231,
Processed = i % 2 == 0,
Image = images[i % images.Length],
});
};
return records;
}
}
}
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Runtime.CompilerServices
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace GridBoundToRuntimeCreatedData
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
gridControl1.DataSource = DataHelper.GetData(10)
' The grid automatically creates columns for the public fields found in the data source.
' Calling the gridView1.PopulateColumns method is not required unless the gridView1.OptionsBehavior.AutoPopulateColumns is disabled
' Create a ComboBox editor that shows available companies in the Company column
Dim riComboBox As New RepositoryItemComboBox()
riComboBox.Items.AddRange(DataHelper.companies)
gridControl1.RepositoryItems.Add(riComboBox)
gridView1.Columns("CompanyName").ColumnEdit = riComboBox
' Specify a different null value text presentation for the Image column
gridView1.Columns("Image").RealColumnEdit.NullText = "[load image]"
'Highlight the RequiredDate cells that match a certain condition.
Dim gridFormatRule As New GridFormatRule()
Dim formatConditionRuleValue As New FormatConditionRuleValue()
gridFormatRule.Column = gridView1.Columns("RequiredDate")
formatConditionRuleValue.PredefinedName = "Red Bold Text"
formatConditionRuleValue.Condition = FormatCondition.Greater
formatConditionRuleValue.Value1 = Date.Today
gridFormatRule.Rule = formatConditionRuleValue
gridFormatRule.ApplyToRow = False
gridView1.FormatRules.Add(gridFormatRule)
gridView1.BestFitColumns()
End Sub
Private Sub btnClearPayment_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnClearPayment.ItemClick
'Change a cell value at the data source level to see the INotifyPropertyChanged interface in action.
gridView1.CloseEditor()
Dim rec As Record = TryCast(gridView1.GetFocusedRow(), Record)
If rec Is Nothing Then
Return
End If
rec.Value = 0
End Sub
Private Sub btnSetPayment_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSetPayment.ItemClick
'Change a cell value at the grid level
gridView1.SetFocusedRowCellValue("Value", 999)
End Sub
End Class
Public Class Record
Implements INotifyPropertyChanged
Public Sub New()
End Sub
Private id_Renamed As Integer
Public Property ID() As Integer
Get
Return id_Renamed
End Get
Set(ByVal value As Integer)
If id_Renamed <> value Then
id_Renamed = value
OnPropertyChanged()
End If
End Set
End Property
Private text As String
<DisplayName("Company")> _
Public Property CompanyName() As String
Get
Return text
End Get
Set(ByVal value As String)
If text <> value Then
If String.IsNullOrEmpty(value) Then
Throw New Exception()
End If
text = value
OnPropertyChanged()
End If
End Set
End Property
Private val? As Decimal
<DataType(DataType.Currency), DisplayName("Payment")> _
Public Property Value() As Decimal?
Get
Return val
End Get
Set(ByVal value? As Decimal)
If Not val.Equals(value) Then
val = value
OnPropertyChanged()
End If
End Set
End Property
Private dt As Date
<DisplayFormat(DataFormatString := "d")> _
Public Property RequiredDate() As Date
Get
Return dt
End Get
Set(ByVal value As Date)
If dt <> value Then
dt = value
OnPropertyChanged()
End If
End Set
End Property
Private state As Boolean
Public Property Processed() As Boolean
Get
Return state
End Get
Set(ByVal value As Boolean)
If state <> value Then
state = value
OnPropertyChanged()
End If
End Set
End Property
Private image_Renamed As Image
Public Property Image() As Image
Get
Return image_Renamed
End Get
Set(ByVal value As Image)
If image_Renamed IsNot value Then
image_Renamed = value
OnPropertyChanged()
End If
End Set
End Property
Public Overrides Function ToString() As String
Return String.Format("ID = {0}, Text = {1}", ID, CompanyName)
End Function
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub OnPropertyChanged(<CallerMemberName> Optional propertyName As String = "")
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Public Class DataHelper
Public Shared companies() As String = { "Hanari Carnes", "Que Delícia", "Romero y tomillo", "Mère Paillarde", "Comércio Mineiro", "Reggiani Caseifici", "Maison Dewey" }
Public Shared images() As Image = { My.Resources.palette_16x16, My.Resources.viewonweb_16x16, My.Resources.design_16x16, My.Resources.piestylepie_16x16, My.Resources.alignhorizontaltop2_16x16, Nothing }
Public Shared Function GetData(ByVal count As Integer) As BindingList(Of Record)
Dim records As New BindingList(Of Record)()
Dim rnd As New Random()
For i As Integer = 0 To count - 1
Dim n As Integer = rnd.Next(10)
records.Add(New Record() With { _
.ID = i + 100, _
.CompanyName = companies(i Mod companies.Length), _
.RequiredDate = Date.Today.AddDays(n - 5), _
.Value = If(i Mod 2 = 0, (i + 1) * 123, i * 231), _
.Processed = i Mod 2 = 0, _
.Image = images(i Mod images.Length) _
})
Next i
Return records
End Function
End Class
End Namespace
The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnEdit 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.
gridView1.Columns["ProductType"].ColumnEdit = ritem;
gridView1.Columns["Name"].ColumnEdit = ritemProducts;
winforms-grid-update-row-style-on-cell-value-change/CS/Form1.cs#L41
RepositoryItemCheckEdit riCheckEdit = new RepositoryItemCheckEdit();
gridView1.Columns["UseStyles"].ColumnEdit = riCheckEdit;
RepositoryItemTrackBar riTrackBar = new RepositoryItemTrackBar();
winforms-buttonedit-customize-button-paddings/CS/ButtonEditWithPadding/Form1.cs#L19
gridView1.Columns[0].ColumnEdit = repositoryItemPaddingButtonEdit1;
gridView1.Columns[1].ColumnEdit = repositoryItemPaddingButtonEdit2;
winforms-richedit-in-an-active-grid-cell/CS/Form1.cs#L58
gridControl1.RepositoryItems.Add(repositoryItemRichTextEdit);
gridView1.Columns["MyData(RichEdit)"].ColumnEdit = repositoryItemRichTextEdit;
winforms-grid-multi-cell-editing/CS/Form1.cs#L27
RepositoryItemComboBox ri = new RepositoryItemComboBox();
gridView1.Columns["Number"].ColumnEdit = ri;
winforms-grid-display-icons-in-data-cells/VB/Form1.vb#L162
checkEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.UserDefined
gridView1.Columns("CheckEdit").ColumnEdit = checkEdit
Dim imageCombo As RepositoryItemImageComboBox = TryCast(gridControl1.RepositoryItems.Add("ImageComboBoxEdit"), RepositoryItemImageComboBox)
gridView1.Columns("ProductType").ColumnEdit = ritem
gridView1.Columns("Name").ColumnEdit = ritemProducts
winforms-grid-update-row-style-on-cell-value-change/VB/Form1.vb#L40
Dim riCheckEdit As RepositoryItemCheckEdit = New RepositoryItemCheckEdit()
gridView1.Columns("UseStyles").ColumnEdit = riCheckEdit
Dim riTrackBar As RepositoryItemTrackBar = New RepositoryItemTrackBar()
winforms-buttonedit-customize-button-paddings/VB/ButtonEditWithPadding/Form1.vb#L17
gridView1.Columns(0).ColumnEdit = repositoryItemPaddingButtonEdit1
gridView1.Columns(1).ColumnEdit = repositoryItemPaddingButtonEdit2
winforms-richedit-in-an-active-grid-cell/VB/Form1.vb#L52
gridControl1.RepositoryItems.Add(repositoryItemRichTextEdit)
gridView1.Columns("MyData(RichEdit)").ColumnEdit = repositoryItemRichTextEdit
gridView1.RowHeight = 120
See Also