简体   繁体   中英

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

I want to show a calendar with years only, not days nor months. Preferably with the DateEdit that DevExpress provides.

You can accomplish this task by handling the DateEdit.Popup event:

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;
    }

more info here

Using PopupDateEditForm will only format the view. But the user has to select the date at last.

Only showing and selecting Year can be achieve using this -

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

this.ColumnYear.ColumnEdit = dropDownYear;

Here I bind DateEdit repo to GridCOlumn.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM