I don't have experience w/ the DevExpress grid, but on the Xceed WPF DataGridControl there's a property called UpdateSourceTrigger
which controls when the data source gets updated (when the user is finished editing an entire row, finished editing a cell, or with every key stroke). I'm sure DevExpress has a similar concept.
This will give you control over when the validation happens. You can put your data validation logic in the FamilyRecord
class itself. When you detect an error put the FamilyRecord
into an error state that will provide a visual cue in the grid.
EDIT:
To determine, upon saving, whether any FamilyRecord
objects in your collection have any errors you'd want something like this:
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
ObservableCollection<FamilyRecord> _familyRecords;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_familyRecords = new ObservableCollection<FamilyRecord>();
_familyRecords.Add(new FamilyRecord(@"Jones", false));
_familyRecords.Add(new FamilyRecord(@"Smith", true));
comboBox1.ItemsSource = _familyRecords;
}
// save button
private void button1_Click(object sender, RoutedEventArgs e)
{
// validate whether any records still have errors before we save.
if (_familyRecords.Any(f => f.HasErrors))
{
MessageBox.Show(@"Please correct your errors!");
}
}
}
public class FamilyRecord
{
public FamilyRecord(string name, bool hasErrors)
{
Name = name;
HasErrors = hasErrors;
}
public string Name { get; set; }
public bool HasErrors { get; set; }
public override string ToString()
{
return this.Name;
}
}
}