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
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:
Thank you for your time,
Rob
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