Hi,
When users enter edit mode for a cell in the xamDataGrid, the whole text of that cell is selected. How do I change it to put the caret position to where the mouse is so that users can insert the text where they want to without clicking again?
Thank you.
Hi Dave,
You have to make sure to call StartEditMode() on the editor before you try to get the TextBox using GetDescendantFromType. If the editor is not in edit mode then there is no TextBox in its visual tree.
I'm using version 15.1 and this solution does not work for me. Specifically I'm getting a null return from Utilities.GetDescendantFromType.
Hi Bach,
I'm glad you were able to resolve your issue. Let me know if you have any further questions on this matter.
Ahh if I change it to this then it will work:
private void CalculateCaretForNumericEditor(XamNumericEditor numEditor, Point pos) { TextBox editorTextBox = (TextBox)Utilities.GetDescendantFromType(numEditor, typeof(TextBox), true); bool wasCollapsed = false; if (editorTextBox.Visibility == System.Windows.Visibility.Collapsed) { wasCollapsed = true; editorTextBox.Visibility = System.Windows.Visibility.Visible; editorTextBox.Measure(numEditor.RenderSize); editorTextBox.Arrange(new Rect(0, 0, numEditor.RenderSize.Width, numEditor.RenderSize.Height)); }
int caretPos = editorTextBox.GetCharacterIndexFromPoint(pos, true);
if (wasCollapsed) editorTextBox.Visibility = System.Windows.Visibility.Collapsed;
if (caretPos >= 0) { editorTextBox.SelectionLength = 0; editorTextBox.SelectionStart = caretPos; } }
In your sample project, just add the following to the resource and you will see the same issue as I am:
<Style TargetType="{x:Type igEditors:XamNumericEditor}"> <Setter Property="PromptChar" Value=""></Setter> <Setter Property="Mask" Value="{}{double:-15.7}"></Setter> </Style>