I have a column in the grid whose style is set to checkbox. Currently it does not matter if the user clicks on the checkbox or anywhere in the cell, the state of the checkbox is toggled. I want the state to toggle only when the user clicks inside the box, otherwise simple select the cell / row.
Hi,
I'm having this exact problem with a checkbox in a grid. I tried playing around with the option suggested on this post but what I find is that no matter where in the cell the user clicks (on the checkbox or outside), the UIElement type is an "Infragistics.Win.UltraWinGrid.UltraGridColumn" so I'm seemingly not able to distinguish between the empty space and the checkbox in the cell.
Thanks,hamanta
Hi Hamanta,
UltraGridColumn is not a UIElement, so I'm not sure what your code is doing, but it doesn't sound right to me. Try searching the Infragistics KB for articles on the ElementFromPoint method. There are articles with sample code that show how to get the cell that the mouse is over.
Here's some sample code I whipped up that works pretty well. Note that the column's CellActivation has to be se to ActivateOnly (or maybe NoEdit) in order for this to work properly.
private void ultraGrid1_MouseUp(object sender, MouseEventArgs e)
{
// Get the grid.
UltraGrid grid = (UltraGrid)sender;
// Get the last UIElement entered.
UIElement lastElementEntered = grid.DisplayLayout.UIElement.LastElementEntered;
// If there is no element, return.
if (lastElementEntered == null)
return;
// Get the cell that the element is in.
UltraGridCell cell = lastElementEntered.GetContext(typeof(UltraGridCell)) as UltraGridCell;
// If there is no cell, return.
if (cell == null)
// Get the cell's editor as a CheckEditor.
CheckEditor checkEditor = cell.EditorResolved as CheckEditor;
// If it's not a CheckEditor, we are not in a CheckBox cell, so return.
if (checkEditor == null)
// Get the CheckIndicatorUIElement. This is the actual checbox within the cell.
// See if the lastElementEntered is a CheckIndicatorUIElement.
CheckIndicatorUIElement checkIndicatorUIElement = lastElementEntered as CheckIndicatorUIElement;
// If the lastElementEntered is not a CheckIndicatorUIElement, so if one of it's ancestors is.
if (checkIndicatorUIElement == null)
checkIndicatorUIElement = lastElementEntered.GetAncestor(typeof(CheckIndicatorUIElement)) as CheckIndicatorUIElement;
if (checkIndicatorUIElement != null)
// If checkIndicatorUIElement is not null, it means the click was on the CheckBox
// and we want to toggle the cell value.
bool cellValue = (bool)cell.Value;
cellValue = !cellValue;
cell.Value = cellValue;
}
else
// If checkIndicatorUIElement is null, it means the click was in a checkbox cell, but
// not on the CheckBox itself, so select the row.
cell.Row.Selected = true;