The latest in the CRM report, query conditions only need years, dateedit and a few time controls are not smooth, obsessive-compulsive disorder rage up the idea of rewriting Dateedit
To create a new class
Cxdateedit
Using devexpress.xtraeditors;using devexpress.xtraeditors.calendar;using devexpress.xtraeditors.controls;using Devexpress.xtraeditors.popup;using devexpress.xtraeditors.repository;using system;using System.collections.generic;using system.linq;using system.text;namespace mlty. business.report{public class Cxdateedit:dateedit {public Cxdateedit () {Properties.vista DisplayMode = DevExpress.Utils.DefaultBoolean.True; Properties.DisplayFormat.FormatString = "yyyy-mm"; Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime; Properties.Mask.EditMask = "yyyy-mm"; Properties.showtoday = false; } protected override Popupbaseform Createpopupform () {if (Properties.vistadisplaymode = = Deve Xpress. Utils.DefaultBoolean.True) return new Customvistapopupdateeditform (this); return new Popupdateeditform (this); } Private DateresultModeenum _datemode = Dateresultmodeenum.firstdayofmonth; Public Dateresultmodeenum Datemode {get {return _datemode;} set {_datemode = value;} The public enum Dateresultmodeenum:int {//Though is a month-date control, but the datetime is definitely 2012-01-01 this format So, this enumeration defines the year-month control to return the first day of the year, or the last day of the month as the value of Dateeditex Firstdayofmonth = 1, lastdayofmonth = 2} } public class Customvistapopupdateeditform:vistapopupdateeditform {public customvistapopupdate EditForm (Dateedit owneredit): Base (Owneredit) {} protected override Dateeditcalendar Createcalendar () { return new Customvistadateeditcalendar (Owneredit.properties, Owneredit.editvalue); }} public class Customvistadateeditcalendar:vistadateeditcalendar {public Customvistadateeditcalen Dar (repositoryitemdateedit item, Object editdate): Base (item, editdate) {} protected override void Init () {base. Init (); This. View = Dateeditcalendarviewtype.yearinfo; Public Cxdateedit.dateresultmodeenum Datemode {get {return (Cxdateedit) this. Properties.owneredit). Datemode; }} protected override void Onitemclick (DevExpress.XtraEditors.Calendar.CalendarHitInfo hitinfo) { Daynumbercellinfo cell = Hitinfo.hitobject as Daynumbercellinfo; if (View = = dateeditcalendarviewtype.yearinfo) {datetime dt = new DateTime (Datetime.year, cel L.date.month, 1, 0, 0, 0); if (Datemode = = CXDateEdit.DateResultModeEnum.FirstDayOfMonth) { Ondatetimecommit (dt, false); } else {DateTime tempdate = dt. AddMonths (1). AddDays (-1); Tempdate = new DateTime (tempdate.year, Tempdate.month, TEMpdate.day, 23, 59, 59); Ondatetimecommit (Tempdate, false); }} else base. Onitemclick (Hitinfo); } } }
Then drag a dateedit on the form xxx and enter XXX. Designer.cs the designer code This.dateedit =new DevExpress.XtraEditors.DateEdit ();
Change to overridden class
Original Blog Address: http://www.cnblogs.com/axing/p/3201066.html
Rewrite the Dateedit control class for Dev to select only years