2016-09-26 415 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; 
      } 
     } 
    } 
}