Hello,
I have had the same problem along with 1 or 2 others here. There is really no event that is fired when you leave the Grid. (Really wish a event was made for thsi scenario)
This is what I do to take care of that event.
(I make no claims that this is the best way to do things but it does seem to work when you leave the Grid. (Unless you click the X to close the program.))
If there is a better way....I am all ears (err eyes).
private void dataGridControl_Site_ID_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
Save_Site_ID_Data_To_Database();
}
private void dataGridControl_Site_ID_GotFocus(object sender, RoutedEventArgs e)
{
Save_Site_ID_Data_To_Database();
}
private void dataGridControl_Site_ID_IsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e)
{
// this method makes sure your changes are saved when you leave the DataGrid (for some reason the
// data grid doesn't fire the LostFocus event when a user leaves the DataGrid....very annoying. This event seems
// to work fairly well. Its called a like 6 times or so for some reason when it is fired.
if (dataGridControl_Site_ID.IsFocused == false)
{
i_static++; // ignore this---using it for testing
dataGridControl_Site_ID.EndEdit();
}
}
private void dataGridControl_Site_ID_LostFocus(object sender, RoutedEventArgs e)
{
Save_Site_ID_Data_To_Database();
}
private void dataGridControl_Site_ID_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Save_Site_ID_Data_To_Database();
}
private void dataGridControl_Site_ID_TargetUpdated(object sender, DataTransferEventArgs e)
{
Save_Site_ID_Data_To_Database();
}