Source isn't updating when IsEditable selected text is deleted

3 posts, 0 answers
  1. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 03 Apr 2012 Link to this post

    Good afternoon,

    I'm having an issue with RadComboBox binding. I'm implementing iNotifyPropertyChanged which works with both get and set properties.
    When I change my selection in the RadComboBox the propertychanged event is raised and works fine.
    However, I have IsEditable="True" & IsReadOnly="True" set
    telerik:RadComboBox x:Name="comboCounties" Grid.Row="4" Grid.Column="1" MinWidth="200" IsEditable="True"
                                         IsReadOnly="True" StaysOpenOnEdit="True" EmptyText="Please select a county" SelectedIndex="-1"
                                         DisplayMemberPath="County" SelectedValuePath="ID" Margin="5"
                                         Style="{StaticResource ComboBoxErrorToolTip}">
                        <telerik:RadComboBox.SelectedValue>
                            <Binding Path="CountyID" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                                <Binding.ValidationRules>
                                    <DataErrorValidationRule></DataErrorValidationRule>
                                </Binding.ValidationRules>
                            </Binding>
                        </telerik:RadComboBox.SelectedValue>
                    </telerik:RadComboBox>


    When I delete all of the text in the ComboBox using the keyboard "back space" key the property changed event isn't raised.
    i.e. I would expect the selected index to be -1 again and the selected value to clear to some default.

    Any idea how I can get around this?

    This problem came to light because my DataErrorValidationRule isn't working properly if the selected ComboBox text has been fully deleted after a selection was made.

    When viewing the Validation Error in a message box it reads 'Value " could not be converted.'

    Here's my validation code for your reference:

    private void GetErrors(StringBuilder sb, DependencyObject obj)
    {
        foreach (object child in LogicalTreeHelper.GetChildren(obj))
        {
            if (child is TextBox)
            {
                TextBox element = child as TextBox;
                if (element == null) continue;
     
                if (Validation.GetHasError(element))
                {
                    sb.Append(element.Text + "Missing detail:\r\n");
                    foreach (ValidationError error in Validation.GetErrors(element))
                    {
                        sb.Append(error.ErrorContent.ToString());
                        sb.Append("\r\r");
                    }
                }
                //Check the children of this object for errors
                GetErrors(sb, element);
            }
            if (child is RadComboBox)
            {
                RadComboBox element = child as RadComboBox;
                if (element == null) continue;
     
                if (Validation.GetHasError(element))
                {
                    sb.Append("Missing detail:\r\n");
                    foreach (ValidationError error in Validation.GetErrors(element))
                    {
                        sb.Append(error.ErrorContent.ToString());
                        sb.Append("\r\r");
                    }
                }
                //Check the children of this object for errors
                GetErrors(sb, element);
            }
        }
    }


    //DataErrorValidationRule
    public string this[string propertyName]
    {
        get
        {
            if (propertyName == "Address1")
            {
                if (string.IsNullOrEmpty(Address1))
                {
                    return "Line 1 is required.";
                }
            }
            if (propertyName == "Postcode")
            {
                if (string.IsNullOrEmpty(Postcode))
                {
                    return "Postcode is required.";
                }
            }
            if (propertyName == "CountyID")
            {
                if (CountyID <= 0)
                {
                    return "County is required.";
                }
            }
            return null;
        }
    }
    //WPF Doesn't use this property
    public string Error
    {
        get { return null; }
    }

    Thank you for your time,

    Rob
  2. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 03 Apr 2012 Link to this post

    I've spent quite a lot of time debugging. It seems that when the selection is cleared in the RadComboBox it doesn't trigger the "set" & "get" property for "CountyID", thus the Validation rule isn't executed.

    The red textbox border does appear but the check isn't execute which returns the string value for the tooltip.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 06 Apr 2012 Link to this post

    Hello,

    Since the IsReadOnly property is set to True no characters different from the ones in the items of the ComboBox can be written or deleted. The Backspace is not working, because the ComboBox is ReadOnly - this is the behaviour by design when in read-only mode - nothing can be changed since is different from the items of the ComboBox. The standard WPF ComboBox works in exactly the same way, which was our objective when we developed the control.

    Regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top