Devexpress dateedit select year and month Z

Source: Internet
Author: User

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

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.