Rewrite the Dateedit control class for Dev to select only years

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.