I am trying to save grid data when the user checks the header checkbox (thus selecting or deselecting everything in the column), but not when the header checkbox changes state due to a user selecting a *cell* checkbox (e.g., when a checkbox in a cell is the first cell in the column to be checked, the header checkbox moves to an intermediate state).
So in the AfterHeaderCheckStateChanged event, I need to tell if it was because the user clicked the header checkbox, or if it was because the user changed a cell checkstate and that caused the header event to fire. I think I can pull it off with some flags set in CellChange and BeforeHeaderCheckStateChanged, but that approach feels rather kludgey. Does anyone know of a more elegant solution?
Thanks,
J
Hello,
Unfortunately, there is no built-in functionality in the control to help you determine what triggered the CheckState changed events. Therefore, you'll have to use the existing event structure and set a flag which you can check and reset in the AfterHeaderCheckStateChanged event.
My recommendation would be to use the MouseClick event on the grid, and check to see if the element under the clicked location is a HeaderCheckBoxUIElement.
private bool checkBoxClicked = false;
private void ultraGrid1_MouseClick(object sender, MouseEventArgs e)
{
UIElement clickedElement = ((UltraGrid)sender).DisplayLayout.UIElement.ElementFromPoint(e.Location);
if (clickedElement != null &&
clickedElement.GetAncestor(typeof(HeaderCheckBoxUIElement)) != null)
this.checkBoxClicked = true;
}
If you require further assistance requiring this functionality, feel free to let me know.
Thank you.
Chris
Hi Chris,
I found your solution helpful. Can I just ask... is it possible to retrieve the column of the clicked HeaderCheckBox UI Element?
Actually, this is a general question. eg. I have an image in a HeaderAppearance of a column, how would I go about determining the column of the given ImageUIElement?
Thanks
Ryan