I have a requirement that I want to make a datagridcolumn which only accepts numeric values(integer) ,when the user enter something other than numbers handle the textbox . I tri
If you dont want to show any validation errors and just want to block any non-numeral value then you can create the DataGridTemplateColumn
and in CellEditingTemplate
use the TextBox
.
and in PreviewTextInput
of the TextBox set e.Handled = true
if value is other than integer:
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
try
{
Convert.ToInt32(e.Text);
}
catch
{
e.Handled = true;
}
}