Like the title says, I am trying to validate my form, but I have an issue getting the combobox value:
<ComboBox Name="ComboBox_Country"
Validation.Error="Validation_Error"
Text="{Binding UpdateSourceTrigger=PropertyChanged,
Path=Form_Country,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}"/>
Which is then validated with my class FormValidation like so:
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Form_Country")
{
if (string.IsNullOrEmpty(Form_Country) || !verifyNumericValue(Form_Country))
result = "Please choose a correct option.";
}
}
I use these functions to call the validation in my form.
private void Confirm_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = _errors == 0;
e.Handled = true;
}
private void Confirm_Executed(object sender, ExecutedRoutedEventArgs e)
{
_generic = new UnidadValidation();
grid_UnidadData.DataContext = _generic;
e.Handled = true;
}
private void Validation_Error(object sender, ValidationErrorEventArgs e)
{
if (e.Action == ValidationErrorEventAction.Added)
_errors++;
else
_errors--;
}
I wish to get the selected value, not the selected text. What is my best option?
string strID = MyCombobox2. SelectedValue. ToString();
Syncfusion WPF input controls allow you to validate user input and display hints if validation fails. If the user input is invalid, a default red border will be shown around the UIElement.
A combobox is a selection control that combines a non-editable textbox and a drop-down listbox that allows users to select an item from a list. It either displays the current selection or is empty if there is no selected item.
Stupid, stupid stupid lack of observation on my part. If you were to change the ComboBox's Text
to SelectedValue
instead like so:
<ComboBox Name="ComboBox_Pais"
Validation.Error="Validation_Error"
SelectedValue="{Binding UpdateSourceTrigger=PropertyChanged,
Path=Escuela_Pais,
ValidatesOnDataErrors=true,
NotifyOnValidationError=true}"/>
One will get the selected value and NOT the text.
For those of you who might want to read on it, I found the original tutorial here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With