首先在In—place Edior Repository添加DateEdit属性
/// <summary>
/// 重写控件时间
/// customRowcelledit事件,指定rowhandle设置其repositoryitem为repositoryitemdateedit
/// </summary>
private void myGridView_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
{
//获取选择列的列名
if (e.Column.FieldName == "值")
{
//e.RowHandle获取要选的行的序号
//e.rowhandle=0,表示选择第一行
string strFiledName = this.myGridView.GetRowCellValue(e.RowHandle, "字段").ToString();
if (this.m_pFeatureCurrent != null && strFiledName!=null)
{
int intFiledIndex = this.m_pFeatureCurrent.Fields.FindFieldByAliasName(strFiledName);
IField pField = this.m_pFeatureCurrent.Fields.get_Field(intFiledIndex);
if (pField.Type == esriFieldType.esriFieldTypeDate)
{
//重写控件
e.RepositoryItem = this.repositoryItemDateEdit1;
}
}
}
}
然后就是需要实现gridView的单元格自定义编辑事件,如下所示。
this.gridView1.CustomRowCellEdit += new DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventHandler(this.gridView1_CustomRowCellEdit);或者直接绑定该事件