Pregunta

Estoy utilizando el Infragistics UltraWinGrid (WIN versión 9.1). El comportamiento por defecto es permitir al usuario que escriba el texto en una celda. Cuando uno copias múltiples celdas de una hoja de cálculo de Excel, los datos sólo la primera de las células se pegarán en el UltraWinGrid.

Uno puede cambiar fácilmente el comportamiento para pegar varias celdas mediante el establecimiento de las células UltraWinGrid ser editable con CellClickAction.CellSelect ; Por desgracia, cuando se hace puede ser que no escribir datos en las celdas.

Así que he intentado modificar estos valores con los eventos para InitializeLayout, KeyDown y KeyPress.

    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;
    }

Ahora puedo clave en los valores en las celdas de nuevo. El problema es, cuando la prensa [Ctrl] [v] para la pasta, la KeyPressEventArgs.KeyChar tiene 22 años y no hay es 'v'. Usted puede ver mi inútil intento de eludir este problema en el delegado ugridQuoteSheet_KeyPress. ¿Cuál es la combinación adecuada de manejo de eventos y configuración CellClickAction para permitir tanto copiar y pegar y escribiendo en una celda de la UltraWinGrid?

¿Fue útil?

Solución

Después de un poco más cuidadosa lectura del post mencionado antes ( http : //forums.infragistics.com/forums/p/23690/86732.aspx#86732 ) He sido capaz de hacer frente a este problema.

Esto puede ser todo manejado dentro del evento KeyPress después de establecer UltraWinGrid.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect; en caso InitializeLayout por supuesto.

    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;
        }
    }

Yo era ignorante de cómo manejar la pulsación de tecla simultánea, [Ctrl] [v]. El Char.IsControl (e.KeyChar) hace el truco aquí.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top