I have a checkbox column that when checked / unchecked, causes the propertychanged event on the datasource to only fire once. If I submit the changes, then the event will fire again, but only once.
Am I missing something or shouldn't the event fire everytime a checkbox is checked/unchecked in the grid? Below is the event handler that I set up on the datasource's propertychanged event as well as the event declaration.
public MainPage(){ InitializeComponent(); context.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(context_PropertyChanged);}
void context_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e){ if (!context.IsLoading && !context.IsSubmitting && e.PropertyName.Equals("HasChanges")) { Row r = gridForecastSchedule.Rows[0]; if (r != null) { HeaderCellControl hcc = (HeaderCellControl)((RowsManager)r.Manager).HeaderRow.Cells["Suppress"].Control; if (hcc != null) { CheckBox headerCB = hcc.Content as CheckBox; if (headerCB != null) { headerCB.Checked -= All_Checked; headerCB.Unchecked -= All_Checked; headerCB.IsChecked = (context.ForecastScheduleWorkModels.Count() > 0 && context.ForecastScheduleWorkModels.Where(a => a.Suppress.Equals(false)).Count() == 0); headerCB.Checked += new RoutedEventHandler(All_Checked); headerCB.Unchecked += new RoutedEventHandler(All_Checked); } } } }
if (context.HasChanges && (!context.IsLoading && !context.IsSubmitting)) btnSave.IsEnabled = true; else btnSave.IsEnabled = false;
if (context.IsSubmitting) { busyDialog.IsBusy = true; }}
Hi,
I’m not sure I understand your application design.
I gather that you are asking if the “context” propertyChanged event would fire when the checkbox is checked and unchecked. But I am not clear about what is the “context”. Is that your grid’s datasource? Is the checkbox bound to your datasource?
Please attach a small sample that duplicates this behavior using Northwind so that I can investigate your implementation.
"context" is the grid's datasource. It is a wcf ria service and I declared it like:
Foreasting.ForecastContext context = new Foreasting.ForecastContext();
The following code is the query that is ran and bound to the gird.
EntityQuery<Foreasting.ForecastScheduleModel> query = context.GetForecastScheduleModelQuery(iForecastID); context.Load(query, (ab) => { gridForecastSchedule.ItemsSource = ab.Entities; EditableColumn suppressCol = gridForecastSchedule.Columns["Suppress"] as EditableColumn; suppressCol.IsReadOnly = true; suppressCol.Visibility = System.Windows.Visibility.Collapsed; btnSave.Visibility = System.Windows.Visibility.Collapsed; busyDialog.IsBusy = false; busyDialog.BusyContent = "Please wait while data is saved..."; }, null);
Editing and saving of the data works fine. The propertyChanged event will only fire the first time a change has been made after data has been loaded or saved. So, if I check a checkbox, the event will fire. If I check a second checkbox, the event does not fire. If I save my changes and then click a checkbox, the event will fire again, but only once until I reload the data or save the data.
So I'm wondering if that's the default behavior or if it should fire every time a checkbox is checked / unchecked?