2010-01-28 80 views
1

我正在使用Infragistics UltraWinGrid(Win 9.1版本)。默認行爲是允許用戶將文本輸入到單元格中。當從Excel電子表格複製多個單元格時,只有第一個單元格的數據將被粘貼到UltraWinGrid中。如何模仿Infragistics UltraWinGrid中的複製粘貼按鍵?

通過將UltraWinGrid單元格設置爲不可編輯,可以輕鬆地更改粘貼多個單元格的行爲CellClickAction.CellSelect;不幸的是,當你這樣做時,你可能不會在單元格中輸入數據。

所以我試圖與InitializeLayout,KeyDown和按鍵響應事件來修改這些設置。

private void ugridQuoteSheet_InitializeLayout(object sender, InitializeLayoutEventArgs e) 
    { 
     e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All; 
     e.Layout.Override.CellClickAction = CellClickAction.CellSelect; 
    } 

    //Event used to circumvent the control key from choking in 
    //the KeyPress event. This doesn't work btw. 
    private void ugridQuoteSheet_KeyDown(object sender, KeyEventArgs e) 
    { 
     UltraGrid grid = (UltraGrid)sender; 

     if (e.Control == true) 
     { 
      e.SuppressKeyPress = true; 
     } 
    } 

    // This event comes after the KeyDown event. I made a lame attempt to stop 
    // the control button with (e.KeyChar != 22). I lifted some of this from 
    // the Infragistics post: http://forums.infragistics.com/forums/p/23690/86732.aspx#86732 
    private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e) 
    { 
     UltraGrid grid = (UltraGrid)sender; 
     if ((grid != null) && (grid.ActiveCell != null) && (!grid.ActiveCell.IsInEditMode) && (e.KeyChar != 22)) 
     { 
      grid.PerformAction(UltraGridAction.EnterEditMode); 
      EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved; 
      editor.TextBox.Text = e.KeyChar.ToString(); 
      editor.TextBox.SelectionStart = 1; 
     } 
    } 

    // This puts the grid in CellSelect mode again so I won't edit text. 
    private void ugridQuoteSheet_AfterCellUpdate(object sender, CellEventArgs e) 
    { 
     this.ugridQuoteSheet.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; 
    } 

我現在可以再次將值輸入到單元格中。問題是,當我按[Ctrl] [V]爲糊狀,在KeyPressEventArgs.KeyChar是22並沒有「V」。你可以在ugridQuoteSheet_KeyPress委託中看到我的無用嘗試繞過這個問題。事件處理和CellClickAction設置的正確組合允許複製粘貼和鍵入到UltraWinGrid的單元中?

回答

1

經過仔細閱讀之前提到的帖子(http://forums.infragistics.com/forums/p/23690/86732.aspx#86732 )後,我已經能夠解決這個問題。

這可以所有設置UltraWinGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect後KeyPress事件內處理;當然在InitializeLayout事件中。

private void ugridQuoteSheet_KeyPress(object sender, KeyPressEventArgs e) 
    { 
     UltraGrid grid = (UltraGrid)sender; 

     if (!Char.IsControl(e.KeyChar) && grid != null && grid.ActiveCell != null && 
      grid.ActiveCell.EditorResolved is EditorWithText && !grid.ActiveCell.IsInEditMode) 
     { 
      grid.PerformAction(UltraGridAction.EnterEditMode); 
      EditorWithText editor = (EditorWithText)grid.ActiveCell.EditorResolved; 
      editor.TextBox.Text = e.KeyChar.ToString(); 
      editor.TextBox.SelectionStart = 1; 
     } 
    } 

我不知道如何處理同時按鍵[ctrl] [v]。該Char.IsControl(e.KeyChar)這裏的伎倆。