我使用的Infragistics UltraWinGrid(版本运9.1)。默认行为是允许用户键入文本到单元格。当从Excel电子表格一个拷贝的多个小区,只有第一单元的数据将被粘贴到所述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?

的小区
有帮助吗?

解决方案

前面提到的柱的多一点仔细阅读后( HTTP ://forums.infragistics.com/forums/p/23690/86732.aspx#86732 )我已经能够解决这个问题。

这可被所有所述按键事件内设置UltraWinGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect后处理;当然在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)的伎俩这里。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top