Can't access SelectionStart unless the Editor is in edit mode

private void ultraGrid1_KeyPress(object sender, KeyPressEventArgs e)
{
    UltraGrid grid = sender as UltraGrid;
    UltraGridCell activeCell = grid == null ? null : grid.ActiveCell;

    // if there is an active cell, its not in edit mode and can enter edit mode
    if (null != activeCell && false == activeCell.IsInEditMode && activeCell.CanEnterEditMode)
    {
        // if the character is not a control character
        if (char.IsControl(e.KeyChar) == false)
        {
            // try to put cell into edit mode
            grid.PerformAction(UltraGridAction.EnterEditMode);

            // if this cell is still active and it is in edit mode...
            if (grid.ActiveCell == activeCell && activeCell.IsInEditMode)
            {
                // get its editor
                EmbeddableEditorBase editor = this.ultraGrid1.ActiveCell.EditorResolved;

                // if the editor supports selectable text
                if (editor.SupportsSelectableText)
                {
                    // select all the text so it can be replaced
                    editor.SelectionStart = 0;
                    editor.SelectionLength = editor.TextLength;

                    if (editor is EditorWithMask)
                    {
                        // just clear the selected text and let the grid
                        // forward the keypress to the editor
                        editor.SelectedText = string.Empty;
                    }
                    else
                    {
                        // then replace the selected text with the character
                        editor.SelectedText = new string(e.KeyChar, 1);

                        // mark the event as handled so the grid doesn't process it
                        e.Handled = true;
                    }
                }
            }
        }
    }
}

 

 

-----------------------------------------------答案:

 

(1)You might be better off trying to do this in the AfterEnterEditMode event, since at that point you don't have to worry about timing issues with the cell going into edit mode.

-Matt

(2)

Thanks ...it works for me on AfterEnterEditMode ..try ..this

 

 

ultxtEditor.SelectionStart = ultxtEditor.Text.Length;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值