Quantcast
Viewing all articles
Browse latest Browse all 18858

WPF DataGridTextColumn.EditingElementStyle MaxLength property not working correctly

Hi,

I'm using a DataGrid in my WPF which is databound to a ObservableCollection. I've set max length property of one of the columns to 5 but it's working very strangely.  It can take the values like "11111" and "22222" but not "99999" and some other 5 digit values values in between.  When it doesn't like the input values, it just creates a red border on that cell and I can't move to next cell using tab key.

Following is my DataGrid defined in XAML and the first column "Merchant ID" is having this issue:

<DataGrid Name="dgMerchID" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" AlternatingRowBackground="Gainsboro" AlternationCount="2" BeginningEdit="dgMerchID_BeginningEdit" SelectionChanged="dgMerchID_SelectionChanged" MouseLeftButtonDown="dgMerchID_MouseLeftButtonDown" CanUserAddRows="True" CanUserDeleteRows="True" CanUserResizeColumns="True" MinHeight="40" MinWidth="400" AutoGenerateColumns="False"><DataGrid.ColumnHeaderStyle><Style TargetType="{x:Type DataGridColumnHeader}"><Setter Property="HorizontalContentAlignment" Value="Center" /></Style></DataGrid.ColumnHeaderStyle><DataGrid.Columns><DataGridTextColumn Binding="{Binding MerchID}" Header="Merchant ID" Width="Auto"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.EditingElementStyle><Style TargetType="TextBox"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/><Setter Property="MinLines" Value="1"/><Setter Property="MaxLength" Value="5"/></Style></DataGridTextColumn.EditingElementStyle></DataGridTextColumn><DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.EditingElementStyle><Style TargetType="TextBox"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/><Setter Property="MinLines" Value="1"/><Setter Property="MaxLength" Value="30"/></Style></DataGridTextColumn.EditingElementStyle></DataGridTextColumn><DataGridTextColumn Header="Dollar Limit" Binding="{Binding Limit}" Width="Auto"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.EditingElementStyle><Style TargetType="TextBox"><Setter Property="TextAlignment" Value="Center"/><Setter Property="MaxLength" Value="6"/></Style></DataGridTextColumn.EditingElementStyle></DataGridTextColumn><DataGridTextColumn Header="Contact" Binding="{Binding Contact}" Width="*"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.EditingElementStyle><Style TargetType="TextBox"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/><Setter Property="MinLines" Value="1"/><Setter Property="MaxLength" Value="20"/></Style></DataGridTextColumn.EditingElementStyle></DataGridTextColumn><DataGridTextColumn Header="Phone" Binding="{Binding Phone}" Width="*"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.EditingElementStyle><Style TargetType="TextBox"><Setter Property="TextWrapping" Value="Wrap"/><Setter Property="TextAlignment" Value="Center"/><Setter Property="MinLines" Value="1"/><Setter Property="MaxLength" Value="12"/></Style></DataGridTextColumn.EditingElementStyle></DataGridTextColumn></DataGrid.Columns></DataGrid>

Thanks,

Vijay


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>