We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

cell got focus

I have one issue related to the cell value entry.
Please take a look at the example attached.
What we want to achieve here is to add a negative sign to the data entered in the cell so the value entered will be automatically changed to negative value.

If the cell got focus and in the edit state, the code works fine. However, when the current cell is moved from one cell to another cell, entering data has some weird behavour. Not sure if it's related to some CellFocusd event.

Please advise.

Hui

NegativeEntry.zip

2 Replies

AD Administrator Syncfusion Team January 5, 2007 04:44 AM UTC

Hi Hui,

Before setting the SelectionStart/Text property of the GridTextBox control, you should call the CurrentCell.BeginEdit method to start the editing mode of the current cell (it also allows setting the focus to the cell editor). Here is a code snippet to show this.

///Else part in the CurrentCellKeyPress event.
if (e.KeyChar != '-')
{
GridCurrentCell cc = gridControl1.CurrentCell;
if (!cc.IsEditing)
cc.BeginEdit(true);
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null && cr.TextBox.SelectionStart == 0)
{
cr.TextBox.Text = "-" + e.KeyChar;
cr.TextBox.SelectionStart = 2;
cr.TextBox.SelectionLength = 1;
e.Handled = true;
}
}

Please refer to the attached sample for implementation.
NegativeEntry.zip

Best Regards,
Haneef


AD Administrator Syncfusion Team January 5, 2007 04:05 PM UTC


Thanks.

>Hi Hui,

Before setting the SelectionStart/Text property of the GridTextBox control, you should call the CurrentCell.BeginEdit method to start the editing mode of the current cell (it also allows setting the focus to the cell editor). Here is a code snippet to show this.

///Else part in the CurrentCellKeyPress event.
if (e.KeyChar != '-')
{
GridCurrentCell cc = gridControl1.CurrentCell;
if (!cc.IsEditing)
cc.BeginEdit(true);
GridTextBoxCellRenderer cr = cc.Renderer as GridTextBoxCellRenderer;
if (cr != null && cr.TextBox.SelectionStart == 0)
{
cr.TextBox.Text = "-" + e.KeyChar;
cr.TextBox.SelectionStart = 2;
cr.TextBox.SelectionLength = 1;
e.Handled = true;
}
}

Please refer to the attached sample for implementation.
NegativeEntry.zip

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon