.net DevExpress日期编辑自定义以仅允许特定日期
我在这里用了这个例子。我想再增加一个功能,我将提供一个只有那些日期才可见的日期数组。我修改了代码并包含了一个属性来接受日期范围,如果提供该属性,则只允许查看和选择这些日期,但我无法理解应该覆盖哪个函数来完成任务。该行为应该与提供编辑器时类似.net DevExpress日期编辑自定义以仅允许特定日期,.net,vb.net,winforms,devexpress,.net-2.0,.net,Vb.net,Winforms,Devexpress,.net 2.0,我在这里用了这个例子。我想再增加一个功能,我将提供一个只有那些日期才可见的日期数组。我修改了代码并包含了一个属性来接受日期范围,如果提供该属性,则只允许查看和选择这些日期,但我无法理解应该覆盖哪个函数来完成任务。该行为应该与提供编辑器时类似MaxValue和MinValue 看看VistaDateEditInfoArgs类的(标准)实现。您可以使用.NET程序集反编译器,如.NET Reflector或ILSpy。 如果相关的datetime不可见/不允许,您可以重写一些虚拟方法并返回null。
MaxValue
和MinValue
看看VistaDateEditInfoArgs类的(标准)实现。您可以使用.NET程序集反编译器,如.NET Reflector或ILSpy。
如果相关的datetime不可见/不允许,您可以重写一些虚拟方法并返回null。
以下是这些方法的源代码(请注意“标准”基于MinValue/MaxValue的检查):
[DevExpress.XtraEditors.ViewInfo.VistaDateEditInfoArgs]
protected virtual DayNumberCellInfo CreateMonthCellInfo(int row, int col)
{
DayNumberCellInfo info;
DateTime date = new DateTime(this.DateTime.Year, (1 + (row * 4)) + col, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Month < this.Calendar.MinValue.Month))
{
return null;
}
return new DayNumberCellInfo(date) { Text = this.Calendar.DateFormat.GetAbbreviatedMonthName (info.Date.Month) };
}
protected virtual DayNumberCellInfo CreateYearCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 10) * 10) - 1;
int year = (num + (row * 4)) + col;
if ((year <= 0) || (year >= 0x2710))
{
return null;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Year < this.Calendar.MinValue.Year))
{
return null;
}
DayNumberCellInfo info = new DayNumberCellInfo(date) {
Text = year.ToString()
};
if ((year < ((this.DateTime.Year / 10) * 10)) || (year > (((this.DateTime.Year / 10) * 10) + 1)))
{
info.State = ObjectState.Disabled;
}
return info;
}
protected virtual DayNumberCellInfo CreateYearsGroupCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 100) * 100) - 10;
int year = num + (((row * 4) + col) * 10);
if ((year < 0) || (year >= 0x2710))
{
return null;
}
int num3 = year + 9;
if (year == 0)
{
year = 1;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (num3 < this.Calendar.MinValue.Year))
{
return null;
}
return new DayNumberCellInfo(date) { Text = year.ToString() + "-\n" + num3.ToString() };
}
看看VistaDateEditInfoArgs类的(标准)实现。您可以使用.NET程序集反编译器,如.NET Reflector或ILSpy。
如果相关的datetime不可见/不允许,您可以重写一些虚拟方法并返回null。
以下是这些方法的源代码(请注意“标准”基于MinValue/MaxValue的检查):
[DevExpress.XtraEditors.ViewInfo.VistaDateEditInfoArgs]
protected virtual DayNumberCellInfo CreateMonthCellInfo(int row, int col)
{
DayNumberCellInfo info;
DateTime date = new DateTime(this.DateTime.Year, (1 + (row * 4)) + col, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Month < this.Calendar.MinValue.Month))
{
return null;
}
return new DayNumberCellInfo(date) { Text = this.Calendar.DateFormat.GetAbbreviatedMonthName (info.Date.Month) };
}
protected virtual DayNumberCellInfo CreateYearCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 10) * 10) - 1;
int year = (num + (row * 4)) + col;
if ((year <= 0) || (year >= 0x2710))
{
return null;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Year < this.Calendar.MinValue.Year))
{
return null;
}
DayNumberCellInfo info = new DayNumberCellInfo(date) {
Text = year.ToString()
};
if ((year < ((this.DateTime.Year / 10) * 10)) || (year > (((this.DateTime.Year / 10) * 10) + 1)))
{
info.State = ObjectState.Disabled;
}
return info;
}
protected virtual DayNumberCellInfo CreateYearsGroupCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 100) * 100) - 10;
int year = num + (((row * 4) + col) * 10);
if ((year < 0) || (year >= 0x2710))
{
return null;
}
int num3 = year + 9;
if (year == 0)
{
year = 1;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (num3 < this.Calendar.MinValue.Year))
{
return null;
}
return new DayNumberCellInfo(date) { Text = year.ToString() + "-\n" + num3.ToString() };
}
你问过DevExpress的人了吗?他们在这类事情上很有帮助。我认为他们在关注这篇文章,所以。@JensKloster是对的。每当涉及到Devexpress时,最好直接询问他们。你通常会在接下来的24小时内得到答案,这通常比这要快,特别是对于像这样复杂(过于本地化)的问题。你问过DevExpress的人吗?他们在这类事情上很有帮助。我认为他们在关注这篇文章,所以。@JensKloster是对的。每当涉及到Devexpress时,最好直接询问他们。你通常会在接下来的24小时内得到答案,这通常比这要快,特别是对于像这样复杂(过于本地化)的问题。方法
CreateMonthCellInfo
甚至没有启动。只有CreateDayCell
正在激发,如果我在CreateDayCell
方法中放入相同的逻辑,则会出现异常。方法CreateMonthCellInfo
甚至没有激发。只有CreateDayCell
正在激发,如果我在CreateDayCell
方法中放入相同的逻辑,则会出现异常。