Pergunta

Estou usando o Infragistics Ultrawingrid (versão da versão 9.1). O comportamento padrão é permitir que o usuário digite texto em uma célula. Quando se copia várias células de uma planilha do Excel, apenas os dados da primeira célula serão colados no Ultrawingrid.

Pode -se alterar facilmente o comportamento para colar várias células, definindo as células ultrawingrid para não ter educação CellClickaction.cellleclect; Infelizmente, quando você faz isso, você não pode digitar dados nas células.

Por isso, tentei modificar essas configurações com os eventos para inicializelayout, keydown e 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;
    }

Agora posso me alternar nos valores nas células novamente. O problema é que, quando pressiono [Ctrl] [V] para pasta, o keyPressEventargs.Keychar é 22 e não há 'V'. Você pode ver minha tentativa fútil de contornar esse problema no delegado UGridQuteSheet_Keypress. Qual é a combinação certa de manuseio de eventos e configuração de cliques celulares para permitir a cola de cópia e digitar uma célula do Ultrawingrid?

Foi útil?

Solução

Depois de um pouco mais de leitura mais cuidadosa do post mencionado antes ( http://forums.infragistics.com/forums/p/23690/86732.aspx#86732 ) Consegui resolver esse problema.

Tudo isso pode ser tratado no evento KeyPress depois de definir o Ultrawingrid.displaylayout.override.cellClickaction = CellClickaction.cellleclect; No evento inicializeLayout, é claro.

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

Eu ignorava como lidar com a imprensa simultânea de teclas, [Ctrl] [v]. O char.iscontrol (e.keychar) faz o truque aqui.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top