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

Manually setting cursor/caret postion.

Hi I''ve got a problem where I am manually calling .BeginEdit on a cell to get it into edit mode, but I need to specify where the user starts typing within the cell text by specifying the caret position. Any ideas how I can go about this? Thanks Martin

1 Reply

Administrator August 5, 2004 09:30 AM UTC

One way you can do this is to get the renderer for the currentcell, and then if it is a textbox, set the SelectionStart and Selection.Len. Here is a snippet that positions the cursor at the end of the text in CurrentCellStartEditing.
private void gridControl1_CurrentCellStartEditing(object sender, System.ComponentModel.CancelEventArgs e)
{
	GridTextBoxCellRenderer tbr = this.gridControl1.CurrentCell.Renderer as GridTextBoxCellRenderer;
	if(tbr != null)
	{
		tbr.TextBox.SelectionStart = tbr.TextBox.Text.Length;
		tbr.TextBox.SelectionLength = 0;
	}
}
Loader.
Live Chat Icon For mobile
Up arrow icon