Home Forums WPF controls Xceed DataGrid for WPF Datagrid CellValidationRule to occur on keypress

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #37249 |

    Hi,

     We are currently using xceed v3.1.9175.12000, and i am trying to implement a custom CellValidationRule  by adding the custom class to a column’s CellValidationRules collection.

    The validation is only fired when the user moves away from that cell.  However when i observe the standard behaviour of an xceed rule (e.g column’s data type is double, and user enters non-numeric characters) i see that the validaiton is fired on each keypress, without the need to tab away from the cell.

    A previous post told me to call the base.Validate, however this field is abstract.

     Is it possible to ensure the validation is fired with each keypress ?

    Regards

    ViN

    Imported from legacy forums. Posted by vin (had 1895 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Vin, 

    You can try to set the UpdateSourceTrigger on the DataGridControl to “CellContentChanged”.

    I hope this helps. 

    Imported from legacy forums. Posted by Michel [Xceed] (had 300 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     It looks like the custom validation method is being called, however the red border around the cell and error tooltip are not appearing.

    The Column is defined as

    <

    xcdg:Column FieldName=FirstName Title=Firstname VisiblePosition=0 Width=100 IsMainColumn=True

    CellContentTemplate={StaticResource DisplayTemplate} CellEditor={StaticResource EditTemplate}>

    <

    xcdg:Column.CellValidationRules>

    <

    local:IsEmptyCellValidationRule />

    </

    xcdg:Column.CellValidationRules>

    </

    xcdg:Column>

     

    where

    <

    DataTemplate x:Key=DisplayTemplate>

    <

    TextBlock Text={Binding}>

    <

    TextBlock.Style>

    <

    Style TargetType=TextBlock>

    <

    Setter Property=Background Value=White/>

    <

    Style.Triggers>

    <

    DataTrigger Binding={Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataRow}}, Path=DataContext, Converter={StaticResource PCT}, ConverterParameter=firstname} Value=True>

    <

    Setter Property=Background Value=Red/>

    </

    DataTrigger>

    </

    Style.Triggers>

    </

    Style>

    </

    TextBlock.Style>

    </

    TextBlock>

    </

    DataTemplate>

    <

    xcdg:CellEditor x:Key=EditTemplate>

    <

    xcdg:CellEditor.EditTemplate>

    <

    DataTemplate>

    <

    TextBox

    Text={xcdg:CellEditorBinding}>

    </

    TextBox>

    </

    DataTemplate>

    </

    xcdg:CellEditor.EditTemplate>

    </

    xcdg:CellEditor>

     

    So the user still has to tab out of the cell for the red border and tooltip to appear.

    Also is there anyway to specify UpdateSourceTrigger=CellContentChanged”  at a column level, rather than for the whole grid ?

    Imported from legacy forums. Posted by vin (had 670 views)

    User (Old forums)
    Member
    Post count: 23064

    I had exacly the same problem.
    I try to have a button desable until the user type a valid value but, if the user type the value and click directly in the button without clicking out the cell or typing TAB button, he able to click in this button.

    Any help ? please find my code below (It’s just a little modification the Xceed validation sample).
    Thanks in advence for your help.

    <Grid>
     
    <Grid.RowDefinitions>
       
    <RowDefinition Height=”*” />
       
    <RowDefinition Height=”Auto” />
     
    </Grid.RowDefinitions>
     
    <Grid.Resources>
       
    <local:ButtonEnabledConverter x:Key=”buttonEnabledConverter” />
     
    </Grid.Resources>
     
    <xcdg:DataGridControl x:Name=”grid”
                           
    Grid.Row=”0″
                           
    ItemsSource=”{Binding Source={StaticResource cvsComposers}}”
                           
    CellEditorDisplayConditions=”MouseOverCell”
                           
    EditTriggers=”BeginEditCommand,ActivationGesture”
                           
    UpdateSourceTrigger=”CellContentChanged”
                           
    ItemScrollingBehavior=”Immediate”>
       
    <xcdg:DataGridControl.View>
         
    <xcdg:TableflowView UseDefaultHeadersFooters=”False” />
        </xcdg:DataGridControl.View>
       
    <xcdg:DataGridControl.Columns>
         
    <xcdg:Column FieldName=”Period”
                      
    CellContentTemplate=”{StaticResource periodDataTemplate}”>
         
    </xcdg:Column>
         
    <xcdg:Column FieldName=”CompositionCount”>
           
    <xcdg:Column.CellValidationRules>
             
    <local:PeriodVSCompositionCountCellValidationRule />
           
    </xcdg:Column.CellValidationRules>
          
    </xcdg:Column>
        
    </xcdg:DataGridControl.Columns>
     
    </xcdg:DataGridControl>
     
    <Button Content=”Button” Grid.Row=”1″
             
    IsEnabled=”{Binding ElementName=grid,
             
    Path=HasValidationError,
             
    Converter={StaticResource buttonEnabledConverter}}”/>
    </Grid>

     

    public class PeriodVSCompositionCountCellValidationRule : CellValidationRule
    {
     
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo culture, CellValidationContext context)
      {
       
    Row parentRow = context.Cell.ParentRow;
       
    Period period;
       
    int compositionCount;
       
    if (context.Cell.FieldName == “Period”)
        {
          period = (
    Period)value;
         
    object compositionCountCellCount = parentRow.Cells[“CompositionCount”].Content;
          compositionCount = (compositionCountCellCount ==
    null) ? 0 : (int)compositionCountCellCount;
        }
       
    else
       
    {
          period = (
    Period)parentRow.Cells[“Period”].Content;
          compositionCount = (value ==
    null) ? 0 : (int)value;
        }
       
    if ((period == Period.Modern) && compositionCount > 49)
        {
         
    return new ValidationResult(false, “Composition count must be less than 50 when the period is set to Modern.”);
        }
       
    return ValidationResult.ValidResult;
      }
    }

     

    Imported from legacy forums. Posted by Salah (had 780 views)

    raghacse
    Participant
    Post count: 1

    Hi,

    I’m also facing same issue.

    I also want to clear the error in a particular cell as soon as user has typed some value(meaning, user no need to press ‘tab’ button to fire the cellvalidation.).

    Is there any solution for the above issue.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.