Devexpress DateEdit选年月 z
Mask与Display只显示年月2012-02这种格式,但用户选择起来还是不爽,体验太差。
效果如下:

代码:
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
{
//虽然是年月控件,但日期Datetime肯定是2012-01-01这种格式
//所以,这个枚举定义了年月控件返回本月的第一天,还是本月的最后一天作为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选年月 z的更多相关文章
- 修改Devexpress DateEdit控件默认的日期格式和日历风格
最近项目中很多地方使用到DevExpress的DateEdit控件,而且设置都是一致(日期格式.选择日期的日历的风格等).每一次都需要设置太痛苦,因此需要寻找一种高效的解决方式. 一. 设置好一个作为 ...
- DevExpress DateEdit 5 常见问题解决方法
1. 如何设置选择的日期大于当天? dateEdit1.Properties.MinValue = DateTime.Now.AddDays(1) 2. 如何做到只显示年.月? var formatS ...
- 关于在datepicker中,只选年月
有这么个需求,datepicker默认是选某个具体的日子的,但是现在只选到年月为止, solution: html如下: <div> <label for="startDa ...
- Devexpress DateEdit控件的值不反馈到数据源的处理方式。
如果在GridControl中要把编辑的值反馈到数据源,可以用Gridview1.PostEdit()方法. 可是在datalayout中使用就会遇到一些问题:比如说DateEdit控件,在保存数据的 ...
- Winform之SpreadSheetGear转DevExpress.XtraSpreadsheet.v13.2 z
DevExpress.XtraSpreadsheet.v13.2 允许用户创建.管理.打印.转换spreadsheet文件而不需要用户安装Office. 什么是Spreadsheet 可以看到最后就是 ...
- Winform使用DevExpress的WaitDialogForm画面 z
使用了DevExpress的WaitDialogForm 在应用程序加载开始时新建一个线程,并将loading画面show起来,在应用程序画面弹出前将该线程终止. 代码: private DevExp ...
- DevExpress GridView属性设置 z
本文主要总结控件的属性设置,附上图片,给大家一个参考.后续会给大家分享功能实现和使用的小技巧. GirdControl是数据的容器,它包含多种显示方式,GridView则是一种二维表格视图. 绑定数据 ...
- DevExpress DateEdit控件选择精确到秒
先看看下面的效果图: 设置以下属性 dateEdit1.Properties.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True; date ...
- DevExpress打印功能介绍 z
一.打印功能说明: 打印功能,我们有多种实现方式,可以根据需要自行选择,我简单的总结下两种方法. (1).使用微软.net框架自带的PrintDocument,这种方式是直接借助Graphics,自行 ...
随机推荐
- js正则函数match、exec、test、search、replace、split使用介绍
match() 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) stringObj 必选项.对其进行查找的 String 对象或字符 ...
- MySQL.. ERROR! The server quit without updating PID file问题解决
不小心将服务器OS给重启了,再启动数据库的时候,出现了很奇怪的问题 [root@dev run]# service mysql restart ERROR! MySQL server PID file ...
- 360抢票 网站维护中 && 你的登录被踢了!
本来在超市犹豫到底该买哪种暖手袋,犹豫了差不多半个多小时,还没决定好,一看时间还有8分钟到10点,遂狂奔回寝室抢票. 结果,360抢票被12306秒了—— 猜测原因是12306的验证码改了(变成动态的 ...
- lintcode:数飞机
数飞机 给出飞机的起飞和降落时间的列表,用 interval 序列表示. 请计算出天上同时最多有多少架飞机? 如果多架飞机降落和起飞在同一时刻,我们认为降落有优先权. 样例 对于每架飞机的起降时间列表 ...
- Codeforces D546:Soldier and Number Game
题目链接 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数 ...
- 如何在React中使用CSS3动画
一.需求 1.在页面添加item时要有渐变效果 2.单击item可删除,带渐变效果 二.代码 1.通过Reacat插件ReactCSSTransitionGroup实现 <!DOCTYPE ht ...
- python 下划线的使用(转载:安生犹梦 新浪博客)
Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from module import *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核 ...
- Dictionary<Key,Value>的用法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- YUV和RGB格式分析
做嵌入式项目的时候,涉及到YUV视频格式到RGB图像的转换,虽然之前有接触到RGB到都是基于opencv的处理,很多东西并不需要我们过多深入的去探讨,现在需要完全抛弃现有的算法程序,需要从内存中一个字 ...
- hibernate--lazy(懒加载)属性
关联映射文件中<class>标签中的lazy(懒加载)属性 Lazy(懒加载):只有在正真使用该对象时,才会创建这个对象 Hibernate中的lazy(懒加载):只有我们在正真使用时,它 ...