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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

cell got focus

Thread ID:

Created:

Updated:

Platform:

Replies:

54263 Jan 4,2007 05:42 PM UTC Jan 5,2007 04:05 PM UTC WinForms 2
loading
Tags: GridControl
Hui Zhong
Asked On January 4, 2007 05:42 PM UTC

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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;