我已经用这里的例子如何创建DateEdit后裔,将允许日单位选择,和多个日期和时间选择。我想增加一个功能,在那里我会提供日期的数组只有那些可见。我已经修改了code,其中包括一个属性接受的日期范围,而如果提供的将只允许看到和选择这些日期,但我无法了解哪些功能我应该重写来完成任务。这样的行为应该是当编辑器提供像的MaxValue
和 MINVALUE
I have used the example here How to create a DateEdit descendant that will allow date unit selection, and multiple dates and periods selection. I wanted to add one more functionality where I would provide an array of dates only those will be visible. I have modified the code and included a property to accept the date ranges, which if provided would only allow seeing and selecting those dates, but I'm unable to understand which function I should override to accomplish the task. The behavior should be like when the editor is supplied MaxValue
and MinValue
这是我的code
推荐答案
看看的(标准)实施VistaDateEditInfoArgs类。你可以使用像.net反射或ILSpy .NET程序集反编译。 有一对夫妇的虚拟方法,你可以覆盖和返回null如果相关的日期时间不应该是可见的/允许的。 下面是这些方法的源$ C $ C(请注意,标准MINVALUE / MaxValue的基础检查):
Take a look at the (standard) implementation of the VistaDateEditInfoArgs class. You may use a .NET assembly decompiler like .NET Reflector or ILSpy. There are a couple of virtual methods you may override and return null if the related datetime should not be visible/allowed. Here is the source code of these methods (please note the "standard" MinValue / MaxValue based checks) :
[DevEx press.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() };
}
我建议你重写你的子类中,这些方法和添加自定义的检查。例如,您可能会以某种方式覆盖CreateMonthCellInfo方法是这样的:
I suggest you to override these methods in your descendant class and add your custom checks. For example, you may override the CreateMonthCellInfo method somehow like this:
protected override DayNumberCellInfo CreateMonthCellInfo(int row, int col)
{
DateTime date = new DateTime(this.DateTime.Year, (1 + (row * 4)) + col, 1);
if (!IsDateAvailable(date))
{
return null;
}
return base.CreateMonthCellInfo(row, col);
}
// Your date availibility check implementation here
private bool IsDateAvailable(DateTime date)
{
// TODO provide implementation
throw new NotImplementedException();
}
相关推荐
最新文章