Int32EditBox setting caret position

Editors for WPF Forum

Posted 6 years ago by Ryan Courreges
Version: 14.1.0601
Avatar

Is there a way to set the caret position to the end of the current value in an Int32EditBox(or other similar edit boxes) when it's loaded?

I have the Int32EditBox as the CellEditingTemplate of a ThemedDataGrid. When I enter edit mode, the Int32EditBox is loaded and on load I call editBox.Focus(true) to force the actual editing part to have focus. If there is no current value this works fine and it's ready for user input. If the edit box already has a value though, the text of the value is highlighted and if any input is given, it overwrites the value. I want the caret to start at the end of the current value rather than with the current entry highlighted.

 

Pretty much the same question for all the other edit box flavors too. The number edit boxes seem to highlight the current value, while the text boxes place the caret at the beginning of the value. At least the text boxes have the CaretIndex property so I can set those.

[Modified 6 years ago]

Comments (4)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ryan,

I believe that functionality is coming from the TextBoxBase control in our primitives, which is the base class for things like MaskedTextBox.  There is an IsAutoSelectAllEnabled property that defaults to true in inlined textboxes.  If you make an implicit Style for TextBoxBase and set that property to false, that might allow you to prevent that behavior from occurring.


Actipro Software Support

Posted 6 years ago by Ryan Courreges
Avatar

I tried the implicit style and it doesnt seem to work. I wasn't able to see a TextBox of any kind in the visual tree of the Int32EditBox. The MaskedTextBox and other TextBoxBase based editors have CaretIndex or SelectionFirstIndex that I can use to make it work, but nothing like that seems to be in the PartEditors.

The only thing I saw of use in the visual tree of the Int32EditBox was a TextBlock which makes me guess you guys have some sort of handler for text input that appends the input to the TextBlock and then you have a caret somewhere as a part. Just a guess though.

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ryan,

It turns out to be more complex since the MaskedTextBox is assigned a style in the part.  Here's an implicit style that you'd effectively need to do for each part:

<Style TargetType="editors:DoublePart">
	<Setter Property="Template">
		<Setter.Value>
			<ControlTemplate TargetType="editors:DoublePart">
				<editors:MaskedTextBox x:Name="PART_MaskedTextBox"
						Style="{DynamicResource {x:Static themes:EditorsResourceKeys.MaskedTextBoxEmbeddedStyleKey}}"
						AutomationProperties.Name="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(AutomationProperties.Name)}"
						Background="{TemplateBinding Background}" Focusable="{TemplateBinding IsEditable}" Margin="{TemplateBinding Padding}"
						Mask="{TemplateBinding Mask}" IsReadOnly="{TemplateBinding IsReadOnly}"
						Text="{editors:SyncBinding StringValue, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" 
						IsAutoSelectAllEnabled="False"
						/>
			</ControlTemplate>
		</Setter.Value>
	</Setter>
</Style>		


Actipro Software Support

Posted 6 years ago by Ryan Courreges
Avatar

That worked. Thanks!

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.