ErrorProvider and comboboxes

ErrorProvider and comboboxes

Old forum URL: forums.lhotka.net/forums/t/178.aspx


Jeff Flowerday posted on Tuesday, May 23, 2006

CSLA .NET 2.0

I can't get the ErrorProvider to flash when I have a null value in a bound ComboBox.  It works just fine with TextBoxes that are bound to validated properties.  Anyone have any ideas?

loBinding = new Binding("SelectedValue", moCMRequest, "TypeID");

cmbType.DataBindings.Add(loBinding);

 

TypeID is a Nullable<Guid> property of my business object.

 

protected override void AddBusinessRules()

{

ValidationRules.AddRule(TypeIDNotNull, "TypeID");

}

private bool TypeIDNotNull(object target, Csla.Validation.RuleArgs e)

{

if (mgTypeID == null)

return false;

else

return true;

}

xal replied on Tuesday, May 23, 2006

Try not to go to the Nullable<T> way... specially if you're relying on databinding.

If I where you I'd declare mgTypeID as regular GUID and use Guid.Empty as null value.
then your combobox can contain the valid values and an extra value which would be Guid.Empty to which you can add a description like <Enter a valid value> (although that last part is not neccesary).
That way the binding WILL set a value of Guid.Empty to your bo and you will get an error.

Your rule should be changed to
if (mgTypeID.Equals(Guid.Empty))
return false;
else
return true;

or simply
return (!mgTypeID.Equals(Guid.Empty))

Andrés

Jeff Flowerday replied on Tuesday, May 23, 2006

I wasn't setting e.Description.  My Bad!!

jwooley replied on Wednesday, May 24, 2006

SelectedValueChanged does not fire when the combobox is cleared. You need to bind to SelectedTextChanged as well.

Jim

Copyright (c) Marimer LLC