如何使用 DevExpress 在 C# 中使用 DateEdit 仅显示年份?

How can I show only the years with a DateEdit in C# with DevExpress?

我想显示一个只有年份的日历,而不是日期或月份。 最好使用DevExpress提供的DateEdit

您可以通过处理 DateEdit.Popup 事件来完成此任务:

private void dateEdit1_Popup(object sender, EventArgs e)
    {
        DateEdit edit = sender as DateEdit;
        PopupDateEditForm form = (edit as IPopupControl).PopupWindow as PopupDateEditForm;
        form.Calendar.View = DevExpress.XtraEditors.Controls.DateEditCalendarViewType.YearInfo;
    }

更多信息here

使用PopupDateEditForm只会格式化视图。但是用户最后必须 select 日期。

只有显示和 selecting 年份才能使用此实现 -

RepositoryItemDateEdit dropDownYear = new RepositoryItemDateEdit();
dropDownYear.Mask.EditMask = "yyyy";
dropDownYear.Mask.UseMaskAsDisplayFormat = true;
dropDownYear.VistaCalendarViewStyle = VistaCalendarViewStyle.YearsGroupView;

this.ColumnYear.ColumnEdit = dropDownYear;

这里我将 DateEdit repo 绑定到 GridCOlumn。