The mask and display formats only display the year, month, and year, 2012-02. however, the user experience is poor.
The effect is as follows:
Code:
Using Microsoft. VisualBasic;
Using system;
Using system. collections;
Using system. Collections. Generic;
Using system. Data;
Using system. diagnostics;
Using devexpress. xtraeditors;
Using devexpress. xtraeditors. calendar;
Using devexpress. xtraeditors. Popup;
Using devexpress. xtraeditors. controls;
Using devexpress. xtraeditors. repository;
Namespace lzja. Common
{
Public class dateeditex: dateedit
{
Public dateeditex ()
{
Properties. vistadisplaymode = 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 = devexpress. 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 ;}
}
Public Enum dateresultmodeenum: int
{
// Although it is the date and year control, the date datetime must be in the format of 2012-01-01
// Therefore, this enumeration defines the date and month control to return the first day of the month, or the last day of the month as the value of dateeditex.
Firstdayofmonth = 1,
Lastdayofmonth = 2
}
}
Public class customvistapopupdateeditform: vistapopupdateeditform
{
Public customvistapopupdateeditform (dateedit owneredit): Base (owneredit ){}
Protected override dateeditcalendar createcalendar ()
{
Return new customvistadateeditcalendar (owneredit. properties, owneredit. editvalue );
}
}
Public class customvistadateeditcalendar: vistadateeditcalendar
{
Public customvistadateeditcalendar (repositoryitemdateedit item, object editdate): Base (item, editdate ){}
Protected override void Init ()
{
Base. INIT ();
This. view = dateeditcalendarviewtype. yearinfo;
}
Public dateeditex. dateresultmodeenum datemode
{
Get {return (dateeditex) 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, cell. Date. month, 1, 0, 0, 0 );
If (datemode = dateeditex. 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 );
}
}
}
Devexpress dateedit select year and month Z