同时处理 AfterRowActivate 和 CellChange 事件
Handling AfterRowActivate and CellChange events simultaneously
我正在使用 UltraGrid,并且我有兴趣处理 AfterRowActivate 和 CellChange 事件。单击布尔类型列和非活动行中的单元格会触发两个事件,首先是 AfterRowActivate,然后是 CellChange。在处理 AfterRowActivate 的方法中,是否有任何方法可以知道该事件是通过单击布尔列中的单元格触发的,因此也将触发 CellChange 事件?
没有直接的方法来查找是否在 AfterRowActivate 事件中单击了布尔单元格。例如,当单击行选择器后激活该行时,可能会触发此事件。您可以尝试获取用户单击的 UIElement。如果 UIElement 是 CheckEditorCheckBoxUIElement,这很可能表明复选框单元格已被单击。
private void UltraGrid1_AfterRowActivate(object sender, EventArgs e)
{
var grid = sender as UltraGrid;
if(grid == null)
return;
// Get the element where user clicked
var element = grid.DisplayLayout.UIElement.ElementFromPoint(grid.PointToClient(Cursor.Position));
// Check if the element is CheckIndicatorUIElement. If so the user clicked exactly
// on the check box. The element's parent should be CheckEditorCheckBoxUIElement
CheckEditorCheckBoxUIElement checkEditorCheckBoxElement = null;
if(element is CheckIndicatorUIElement)
{
checkEditorCheckBoxElement = element.Parent as CheckEditorCheckBoxUIElement;
}
// Check if the element is CheckEditorCheckBoxUIElement. If so the user clicked
// on a check box cell, but not on the check box
else if(element is CheckEditorCheckBoxUIElement)
{
checkEditorCheckBoxElement = element as CheckEditorCheckBoxUIElement;
}
// If checkEditorCheckBoxElement is not null check box cell was clicked
if(checkEditorCheckBoxElement != null)
{
// You can get the cell from the parent of the parent of CheckEditorCheckBoxUIElement
// Here is the hierarchy:
// CellUIElement
// EmbeddableCheckUIElement
// CheckEditorCheckBoxUIElement
// CheckIndicatorUIElement
// Find the CellUIElement and get the Cell of it
if(checkEditorCheckBoxElement.Parent != null && checkEditorCheckBoxElement.Parent.Parent != null)
{
var cellElement = checkEditorCheckBoxElement.Parent.Parent as CellUIElement;
if(cellElement != null)
{
var cell = cellElement.Cell;
}
}
}
}
我正在使用 UltraGrid,并且我有兴趣处理 AfterRowActivate 和 CellChange 事件。单击布尔类型列和非活动行中的单元格会触发两个事件,首先是 AfterRowActivate,然后是 CellChange。在处理 AfterRowActivate 的方法中,是否有任何方法可以知道该事件是通过单击布尔列中的单元格触发的,因此也将触发 CellChange 事件?
没有直接的方法来查找是否在 AfterRowActivate 事件中单击了布尔单元格。例如,当单击行选择器后激活该行时,可能会触发此事件。您可以尝试获取用户单击的 UIElement。如果 UIElement 是 CheckEditorCheckBoxUIElement,这很可能表明复选框单元格已被单击。
private void UltraGrid1_AfterRowActivate(object sender, EventArgs e)
{
var grid = sender as UltraGrid;
if(grid == null)
return;
// Get the element where user clicked
var element = grid.DisplayLayout.UIElement.ElementFromPoint(grid.PointToClient(Cursor.Position));
// Check if the element is CheckIndicatorUIElement. If so the user clicked exactly
// on the check box. The element's parent should be CheckEditorCheckBoxUIElement
CheckEditorCheckBoxUIElement checkEditorCheckBoxElement = null;
if(element is CheckIndicatorUIElement)
{
checkEditorCheckBoxElement = element.Parent as CheckEditorCheckBoxUIElement;
}
// Check if the element is CheckEditorCheckBoxUIElement. If so the user clicked
// on a check box cell, but not on the check box
else if(element is CheckEditorCheckBoxUIElement)
{
checkEditorCheckBoxElement = element as CheckEditorCheckBoxUIElement;
}
// If checkEditorCheckBoxElement is not null check box cell was clicked
if(checkEditorCheckBoxElement != null)
{
// You can get the cell from the parent of the parent of CheckEditorCheckBoxUIElement
// Here is the hierarchy:
// CellUIElement
// EmbeddableCheckUIElement
// CheckEditorCheckBoxUIElement
// CheckIndicatorUIElement
// Find the CellUIElement and get the Cell of it
if(checkEditorCheckBoxElement.Parent != null && checkEditorCheckBoxElement.Parent.Parent != null)
{
var cellElement = checkEditorCheckBoxElement.Parent.Parent as CellUIElement;
if(cellElement != null)
{
var cell = cellElement.Cell;
}
}
}
}