2016-09-26 88 views
0

我正在使用UltraGrid,并且有兴趣处理AfterRowActivate和CellChange事件。单击布尔类型列和非活动行中的单元格会触发这两个事件,首先是AfterRowActivate,然后是CellChange。在处理AfterRowActivate的方法中,是否有任何方法知道该事件是通过单击布尔列中的单元格触发的,因此也会触发CellChange事件?同时处理AfterRowActivate和CellChange事件

+0

有一个AfterCellActivate在CellChanged事件之前引发,包含有关单击单元格的信息。 AfterRowActivate接收到正常的EventArgs参数,但没有任何关于当前单元格的信息。为什么你需要处理AfterRowActivate? – Steve

+0

问题是,我在UltraDockManager中有一个UltraPanel,并且想要显示或隐藏面板,具体取决于活动行是否检查了布尔列。所以我需要AfterRowActivate来显示或隐藏面板,但同样需要CellChange。 AfterCellActivate在CellChange之前但在AfterRowActivate之后引发之后,因此在处理AfterRowActivate的方法中,我不知道布尔单元格的值是否会因为只有动作而被改变(单击布尔列的单元格,活跃的行)。任何想法都会非常有帮助。 @Steve – Robin

回答

0

没有直接的方法来查找是否在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; 
      } 
     } 
    } 
}