Reputation: 123
I am building a wpf application, I have a DataGrid
where user can edit cells, when I click on a cell for edit, the total text is selected like in this image:
I want the text to be like in this image when the user click on a cell for edit:
Upvotes: 0
Views: 124
Reputation: 921
CS
Implement CustomDataGrid, which inhherites DataGrid
public class CustomDataGrid : DataGrid
{
protected override void OnPreparingCellForEdit(DataGridPreparingCellForEditEventArgs e)
{
base.OnPreparingCellForEdit(e);
var textbox = e.EditingElement as TextBox;
if (textbox == null) return;
textbox.Focus();
textbox.CaretIndex = textbox.Text.Length;
}
}
XAML
<CustomDataGrid>
</CustomDataGrid>
Upvotes: 1