DevExpress中DateEdit控件设置
只显示年
this.dateEdit1.Properties.Mask.EditMask = "yyyy";
this.dateEdit1.Properties.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearsGroupView;
this.dateEdit1.Properties.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearsGroupView;
数据绑定时,dateEdit1绑定在一个string类型的字段Nianfen,该字段只存储年,如2018。
如果绑定在EditValue时,总莫名其妙不显示,可能是与日期格式不符。
更改dateEdit1值时,绑定字段值会变为完整日期格式的值,如2018-01-01 12:12:12.
解决办法:
1、数据绑定在DateEdit1的Text属性,注意:绑定代码要写在初始函数里,不能写在designer.cs里,否则会提示“Text不可写”,实际上是可写的。
2、this.dateEdit1.Properties.Mask.UseMaskAsDisplayFormat = false;
只显示月
this.dateEdit1.Properties.Mask.EditMask = "MM月";
this.dateEdit1.Properties.ShowMonthNavigationButtons = DevExpress.Utils.DefaultBoolean.False;
this.dateEdit1.Properties.ShowToday = false;
this.dateEdit1.Properties.ShowYearNavigationButtons = DevExpress.Utils.DefaultBoolean.False;
this.dateEdit1.Properties.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
this.dateEdit1.Properties.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;
只显示年月
this.dateEdit1.Properties.Mask.EditMask = "yyyy年MM月";
this.dateEdit1.Properties.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
this.dateEdit1.Properties.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;