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;