Skip to content

Latest commit

 

History

History
48 lines (41 loc) · 1.49 KB

kb-datapager-allow-only-numbers-in-datapagertextbox.md

File metadata and controls

48 lines (41 loc) · 1.49 KB
title description page_title type slug position tags ticketid res_type
Allow Numbers Only in the PageIndex TextBox of RadDataPager
Allow entering only numeric input in the DataPagerTextBox.
Disable Alphabetical Characters in the Page Index Input of DataPager
how-to
kb-allow-only-numbers-in-datapagertextbox
0
pageindex,datapagertextbox,regex
1480886
kb

Environment

Product Version 2019.3.1023
Product RadDataPager for WPF

Description

Allow entering only numeric input in the DataPagerTextBox that shows the current page index.

Solution

Subscribe to the Loaded event of RadDataPager in order to get the DataPagerTextBox control representing the page index input. Then subscribe to the PreviewTextInput event of DataPagerTextBox. In the handler, you can check the current Text and if there is a non-numeric value, set the Handled property of the event arguments to True. This will cancel the input.

[C#]

{{region kb-allow-only-numbers-in-datapagertextbox-0}} private void RadDataPager_Loaded(object sender, RoutedEventArgs e) { var dataPagerTextBox = this.radDataPager.FindChildByType(); dataPagerTextBox.PreviewTextInput += Tb_PreviewTextInput; }

private void DataPagerTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
	Regex regex = new Regex("[^0-9]+");
	e.Handled = regex.IsMatch(e.Text);
}

{{endregion}}