RADCombo not showing validation error in UI.

4 posts, 0 answers
  1. Bhaskar
    Bhaskar avatar
    1 posts
    Member since:
    Sep 2009

    Posted 02 Oct 2009 Link to this post

    Hello,

    In one of page I have a Combo the XAML is given below.

    <telerikInput:RadComboBox IsEditable="True" LostFocus="txtHairColor_LostFocus" ItemTemplate="{StaticResource ComboBoxCustomTemplate}"  telerik:TextSearch.TextPath="Code" FilteringMode="Contains" IsTextSearchEnabled="True" x:Name="txtHairColor" Height="24" Width="100" BorderBrush="Gray" BorderThickness="1 0 1 0" VerticalAlignment="Center" validation:ValidationSummary.ShowErrorsInSummary="False"  Text ="{Binding Path=Color, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"

    Since user can Type-in any value in the combobox, in the LostFocus event, I am checking the text and if it's not from within the list, then I am clearing it. Below is the code for the event
    private void txtHairColor_LostFocus(object sender, RoutedEventArgs e)  
            {  
                RadComboBox cmb = (RadComboBox)sender;  
                if (cmb != null)  
                {  
                    List<SelectItem> item = (List<SelectItem>)cmb.ItemsSource;  
                    if (item != null)  
                    {  
                        bool isFound = false;  
                        item.ForEach(delegate(SelectItem temp) { if (temp.Code == cmb.Text) { isFound = truereturn; } });  
                        if (!isFound)  
                        {  
                            cmb.Text = "";  
                            BindingExpression be = cmb.GetBindingExpression(RadComboBox.TextProperty);  
                            be.UpdateSource();  
                        }  
                    }  
                }  
            } 

    Where I am binding ItemsSource with List<SelectItem>, SelectItem is a custom class with two property, Code and Description.

    And in the Entity class (which I am setting as DataContext property) I have "Color" property defined as following
    public string Color  
            {  
                get 
                {  
                    return this._Color  
                }  
                set 
                {  
                    if (value.Length == 0)  
                    {  
                        throw new Exception("Please select Hair color.");  
                    }  
                        this._Color= value;  
                        OnPropertyChanged("Color");  
                }  
            } 

    So if I type any arbitary value in the combo, it's clearing it up and also throwing the BindingValidationError, but the ComboBox isn't showing up the Error. Also Other controls(mostly TextBox) are showing up the validation error message.

    To show the validation error I am using Tooltip and the code is given below.
    <ControlTemplate x:Key="ValidationToolTipTemplate" TargetType="ToolTip">  
                    <Grid x:Name="Root" Margin="10,-5" RenderTransformOrigin="0,0" Opacity="0">  
     
                        <Grid.RenderTransform>  
                            <TranslateTransform x:Name="xform" X="-25" />  
                        </Grid.RenderTransform>  
     
                        <vsm:VisualStateManager.VisualStateGroups>  
                            <vsm:VisualStateGroup Name="OpenStates">  
                                <vsm:VisualStateGroup.Transitions>  
                                    <vsm:VisualTransition GeneratedDuration="0" />  
                                    <vsm:VisualTransition To="Open" GeneratedDuration="0:0:0.2">  
                                        <Storyboard>  
                                            <DoubleAnimation Storyboard.TargetName="xform" 
                                                    Storyboard.TargetProperty="X" To="0" 
                                                    Duration="0:0:0.2">  
                                                <DoubleAnimation.EasingFunction>  
                                                    <BackEase Amplitude=".3" EasingMode="EaseOut" />  
                                                </DoubleAnimation.EasingFunction>  
                                            </DoubleAnimation>  
                                            <DoubleAnimation Storyboard.TargetName="Root" 
                                                    Storyboard.TargetProperty="Opacity" To="1" 
                                                    Duration="0:0:0.2" />  
                                        </Storyboard>  
                                    </vsm:VisualTransition>  
                                </vsm:VisualStateGroup.Transitions>  
                                <vsm:VisualState x:Name="Closed">  
                                    <Storyboard>  
                                        <DoubleAnimation Storyboard.TargetName="Root" 
                                                Storyboard.TargetProperty="Opacity" To="0" Duration="0" />  
                                    </Storyboard>  
                                </vsm:VisualState>  
                                <vsm:VisualState x:Name="Open">  
                                    <Storyboard>  
                                        <DoubleAnimation Storyboard.TargetName="xform" 
                                                Storyboard.TargetProperty="X" To="0" Duration="0" />  
                                        <DoubleAnimation Storyboard.TargetName="Root" 
                                                Storyboard.TargetProperty="Opacity" To="1" Duration="0" />  
                                    </Storyboard>  
                                </vsm:VisualState>  
                            </vsm:VisualStateGroup>  
                        </vsm:VisualStateManager.VisualStateGroups>  
     
                        <Border Margin="4,4,-4,-4" Background="#052A2E31" CornerRadius="5" />  
                        <Border Margin="3,3,-3,-3" Background="#152A2E31" CornerRadius="4" />  
                        <Border Margin="2,2,-2,-2" Background="#252A2E31" CornerRadius="3" />  
                        <Border Margin="1,1,-1,-1" Background="#352A2E31" CornerRadius="2" />  
     
                        <Border Background="#FFDC000C" CornerRadius="2" />  
                        <Border CornerRadius="2">  
                            <TextBlock Foreground="White" Margin="8,4,8,4" MaxWidth="250" 
                                    TextWrapping="Wrap" 
                                    Text="{Binding (Validation.Errors)[0].ErrorContent}" />  
                        </Border>  
                    </Grid>  
     
                </ControlTemplate> 

    Any idea what I am doing wrong?

    Thanks
    Bhaskar



  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 06 Oct 2009 Link to this post

    Hi Bhaskar,

    The problem is that RadComboBox does not have validation states in its template. We have this feature in our plans for Q3 2009 and it is almost ready, so you will be able to get the updated assemblies next week when we release Beta 2.

    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Michel Depoix
    Michel Depoix avatar
    1 posts
    Member since:
    Aug 2009

    Posted 21 Oct 2009 Link to this post

    Hi Valeri,

    I have the same problem than Bhaskar.
    When do you think that Q3 beta 2 will be available?

    Thanks.

    Thierry
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 21 Oct 2009 Link to this post

    Hi Thierry,

    Beta2 is already available. You could download the installation from the downloads section of www.telerik.com.

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top