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

setting the cursor in the currentcell on keypress

I have a gridcontrol with currency cells and i want the user to be able to enter negative numbers (hit the negative sign) without clicking into the cell. I can handle the key press and have the entire cell contents selected by doing a CurrentCell.BeginEdit(). But what i really want is no selection, just the cursor active inside the cell. How can i do this?
We are using version 5.2.0.25.
Thanks,
Julie


3 Replies

RC Rajadurai C Syncfusion Team November 13, 2008 11:20 AM UTC

Hi Julie,

Thanks for your interest in Syncfusion products.

This feature can be achieved by means of the following codesnippet in CurrentCellKeyPress event handler.


void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridCurrencyTextBoxCellRenderer cb = cc.Renderer as GridCurrencyTextBoxCellRenderer;
if(e.KeyChar == '-')
{
if(!this.gridControl1.CurrentCell.IsEditing)
{
this.gridControl1.CurrentCell.BeginEdit();
cb.ReplaceSel("$0");
cc.Renderer.ControlValue = string.Empty;
}
}
}


Please refer the following sample that does the same.
http://websamples.syncfusion.com//samples/Grid.Windows/F77630/main.htm

Regards,
Rajadurai



JL Julie Levy November 18, 2008 12:14 AM UTC

Thanks for your response and the sample code.
However, the behavior i need is that the "-" still toggles the sign of the value in the cell, the same as if the user first clicked into the cell and then hit the "-".

I found that the following works:
this.CurrentCell.MoveTo(this.CurrentCell.RowIndex, this.CurrentCell.ColIndex, GridSetCurrentCellOptions.SetFocus)

Thanks.



RC Rajadurai C Syncfusion Team November 18, 2008 06:46 AM UTC

Hi Julie,

Thanks for your update.

Glad to hear that your issue has been solved. Please let us know if you have any further concerns.

Regards,
Rajadurai


Loader.
Live Chat Icon For mobile
Up arrow icon