我目前有2个控件。第一个控件是名为DisbursalDatePicker的DatePicker,第二个控件是具有多个列的网格。唯一重要的列是日期列。更改日期时,会进行验证检查以确定row.date是否在DisbursalDatePicker之前,如果它随后显示验证错误。
验证工作完美且没有错误。 displaystartdate正在为gridrows正常工作。但是如果存在验证错误,则由于某种原因,displaystartdate将设置为行的当前选定日期而不是DisbursalDatePicker。
private void DisbursalDatePicker_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
foreach (ScriptDTO script in RadGridView1.Items.OfType<ScriptDTO>())
{
if (script.Date <= DisbursalDatePicker.SelectedDate)
{
script.SetError("Date", "Must be after disbursal");
}
else
{
script.ClearErrors();
}
}
}
脚本DTO
public class ScriptDTO : INotifyPropertyChanged, IDataErrorInfo
{
...
private DateTime _date;
public DateTime Date
{
get { return _date; }
set { _date = value; OnPropertyChanged("Date"); }
}
private readonly Dictionary<string, string> errors = new Dictionary<string, string>();
public void ClearErrors()
{
this.errors.Clear();
}
public void SetError(string propertyName, string error)
{
string currentPropertyError;
if (this.errors.TryGetValue(propertyName, out currentPropertyError))
{
this.errors.Remove(propertyName);
}
this.errors.Add(propertyName, error);
this.OnPropertyChanged(propertyName);
}
public string GetError(string propertyName)
{
string result;
if (this.errors.TryGetValue(propertyName, out result))
{
return result;
}
return null;
}
public string this[string columnName]
{
get
{
return this.GetError(columnName);
}
}
public string Error
{
get
{
return null;
}
}
...
}
查看
<telerik:GridViewDataColumn Header="Date" DataMemberBinding="{Binding Date, StringFormat=d}">
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Date}" DisplayDateStart="{Binding StartDate, Mode=TwoWay}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
foreach (var script in ScheduleScripts)
{
script.StartDate = DisbursalDate;
}