C #: changing caret position in DataGridView
In the TextBox, I could use textBox1.SelectionStart = 4
. How do I do this in DataGridView?
edit for clarification: let's assume that a specific cell is already selected and in edit mode. If I press the right arrow key, the caret moves to the desired position across any text in that cell. I want to create a button that does the same.
+1
a source to share
4 answers
You need to get the TextBox via the DataGridView EditingControlShowing event.
Store this as a member variable, and when you need to, access the textBox element and set the SelectionStart as you wrote above.
Sort of:
dataGrid.EditingControlShowing += this.dataGrid_EditingControlShowing;
and
void dataGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if(this.dataGrid.CurrentCell != null && e.Control is TextBox)
{
this.currentTextBox = (TextBox)e.Control;
}
}
0
a source to share