Hi
I have UltraCombo bound to data source. It has also one unbound column of checkbox type. Initially all rows are unchecked.
I discovered that when I click on this column's header check box the Value property changes step-by-step i.e. I have a series of ValueChanged events with 1st row checked then 1st and 2nd rows checked etc.
Problem is that after changing the value I have to hit database so when I try to check all rows it just stucks so I would like to have one query to database after check of uncheck all rows with one click.
I played with OnBeforeHeaderCheckBoxStateChanged method (using control inherited directly from UltraCombo) and here is sample code:
protected override void OnBeforeHeaderCheckBoxStateChanged(BeforeHeaderCheckStateChangedEventArgs e) { base.OnBeforeHeaderCheckBoxStateChanged(e); switch (e.NewCheckState) { case CheckState.Checked: Value = Rows.Select(x => x.Cells[ValueMember].Value).ToList(); e.Cancel = true; break; case CheckState.Unchecked: Value = new List<object>(); e.Cancel = true; break; } }
After doing this I almost got what I want but the problem is that the text in displaying part of combo is not being updated untill combo lost its focus even the rows are checked when I open dropdown again. Am I doing something wrong is there any way to do it better?
Thanks
Hi,
It seems like a better thing to do would be to simply set a flag inside of OnBeforeHeaderCheckBoxStateChanged. Then check that flag inside ValueChanged and if the flag is set, skip your ValueChanged code.
Then in the OnAfterHeaderCheckBoxStateChanged, do your processing for ValueChanged.
Hi Mike
Thanks for the quick response.
Yes everything seems to work fine, here is the code if someone would like to use it
private bool valueIsChangedAfterHeaderChecked; protected override void OnValueChanged(EventArgs e) { if (valueIsChangedAfterHeaderChecked) return; base.OnValueChanged(e); } protected override void OnBeforeHeaderCheckBoxStateChanged(BeforeHeaderCheckStateChangedEventArgs e) { base.OnBeforeHeaderCheckBoxStateChanged(e); switch (e.NewCheckState) { case CheckState.Checked: valueIsChangedAfterHeaderChecked = true; break; case CheckState.Unchecked: valueIsChangedAfterHeaderChecked = true; break; } } protected override void OnAfterHeaderCheckBoxStateChanged(AfterHeaderCheckStateChangedEventArgs e) { if (valueIsChangedAfterHeaderChecked) { valueIsChangedAfterHeaderChecked = false; OnValueChanged(EventArgs.Empty); } base.OnAfterHeaderCheckBoxStateChanged(e); }