NVL Combobox when revisiting doesn't show error icon

NVL Combobox when revisiting doesn't show error icon

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


tiago posted on Tuesday, October 06, 2009

I have a NVL combobox that is setup like this:

this.docTypeNVLComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.docBindingSource, "DocTypeID", true));
this.docTypeNVLComboBox.DataSource = this
.docTypeNVLBindingSource;
this.docTypeNVLComboBox.DisplayMember = "Value"
;
this.docTypeNVLComboBox.Name = "docTypeNVLComboBox"
;
this.docTypeNVLComboBox.ValueMember = "Key";

When I create a new document, as I have no default value, the combo has no selected item and shows the red icon from the error provider. If I enter the combo box it behaves as the La Brea tar pit and doesn't allow me to leave until I select an item.

If I come back and type garbage or just delete every character, when I try to leave it lets me go away, although it doesn't change the databindings. If I change anything else in the form, that combobox re-shows the last selected item.

On the other hand, if I come back, change the selected item to another item and after that type garbage or delete every character, then it shows me the red icon and behaves like a tar pit again.

Of course I can solve the problem with the binding Parse and Format handlers. But that means to much coding.

Is there a way (meaning property) to make the combobox always show the red icon when there is no valid item selected?

JonnyBee replied on Tuesday, October 06, 2009

Hi,

Is the datatype for Key and DocTypeID excact same? They should be ..

What is the Style of your combobox? DropDownList?

I prefer to add a "system" item that says something like "(not selected)" and has a Key (ex -1 which is also the defaultvalue) that is not considered a valid value in ValidationRules. This allows the user to leave the field without selecting a value and leaves the error icon in place.

And what is the message you get on the red icon? It may not be from your BOs validation rules but from the databinding. If you want an error icon on the ComboBox when no item is selected then your BOs validation rules should fail on property DocTypeID. The ErrorProvider or ErrorWarnInfoProvider connected to your datasource will show the ErrorIcon and message.

I would also recommend reading the DataBinding FAQ

Copyright (c) Marimer LLC