Missing something simple?

Missing something simple?

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


ajj3085 posted on Tuesday, May 30, 2006

Hi all,

I must be missing something simple.

I have a textbox, bound to a property on my BO.  I'd like to set an error provider to display the details of the error message (a value is required).

I'm not quite sure how to setup the error provider so that it displays messages regarding only that property on the BO.

What do I need to do to get the error provider properly setup?

Thanks
Andy

SoftwareArchitect replied on Tuesday, May 30, 2006

If you are using a BindingSource (which with 2.0 I think you should be) than you need to set the ErrorProvider1.DataSource = YourBindingSource.

That way, it catches the error events raised by databinding and displays them.

Mike

ajj3085 replied on Tuesday, May 30, 2006

I got that far, but the error provider doesn't appear.  Also, how to I tell the ErrorProvider which property to care about?  If propX is valid, but propY is not, how do I specify ErrProv2 should only show if propY is not valid?

Thanks
Andy

ajj3085 replied on Wednesday, May 31, 2006

Anybody using ErrorProviders?

xal replied on Wednesday, May 31, 2006

I am... I just did ErrProvider.Datasource = BindingManager1.
Make sure your rules are being fired, that you're returning false if the rule is broken and that you have set e.Description inside the rule method. Are you using databinding? how did you set it up? doid you do drag and drop from datasources panel? (It worked just fine for me that way...)

Andrés

ajj3085 replied on Wednesday, May 31, 2006

I have a MergeBindingSource, which is bound to my BO.  I have the ErrorProvider's datasource set to the MergeBindingSource.

On form load, I have
Org1ReqdErrorProvider.SetIconAlignment( Org1TextBox, ErrorIconAlignment.MiddleRight );

The text box is within a group box which is within a panel.

Yes, the Validation rules are firing, and the BrokenRulesCollection contains all the violated rules I expect.

Thanks
Andy

RockfordLhotka replied on Wednesday, May 31, 2006

Is the PropertyChanged event firing? For the right property (you don't have any typos - including upper/lower case)?

I use the ErrorProvider all the time - create the form with drag-and-drop binding, then set the ErrorProvider control's DataSource to the same BindingSource control as the detail controls and it just works.

ajj3085 replied on Wednesday, May 31, 2006

Yes, the property changed is firing properly.

My BO has 3 properties; Org1, Org2, and Action.

MergeBindingSource.DataSource = bo;
Org1BindingSource.DataSource = MergeBindingSource;
Org1BindingSource.DastaMember = "Org1";
Org2BindingSource.DataSource = MergeBindingSource;
Org2BindingSource.DastaMember = "Org2";
ErrorProv.DataSource = MergeBindingSource;
ErrorProv.DataMember = "Org1";

When the form is loaded, this code executes:
bo = MergeOrgs.NewMergeOrgs();
MergeBindingSource.DataSource = bo;

Via some button clicks, the user selects values for Org1 and Org2.  The screen updates properly (The name of the Org is displayed in a text box, and the list of departments belonging to the org is displayed in a DataGridView (the Bindingsources for those I've omitted).

The form itself has 3 panels, which have different sets of controls.  On load, the first panel is displayed (which displays the info I meantioned above) and the others are hidden.  The ErrorProvider's icon alignment is set to the text box (which is on the panel).  The object always starts out as invalid, but even if I assume a value to Org1 and then set Org1 back to null, the provider never shows.  (Although broken rules are updated).

Could it have something to do with the panels?  I don't think so, because I also tried aligning the provider with a button which isn't covered by a panel.

Andy

RockfordLhotka replied on Wednesday, May 31, 2006

I don't know that I've ever set the DataMember for an ErrorProvider (unless the designer did it for me and I didn't know).
 
Rocky

ajj3085 replied on Wednesday, May 31, 2006

Even unset I still don't get it to work for me.

xal replied on Wednesday, May 31, 2006

Shouldn't you bind your error provider to Org1BindingSource if you want the error provider to pop up for errors in Org1BindingSource? The controls you say are bound to Org1BindingSource, not to MergeBindingSource, right?

Andrés

ajj3085 replied on Wednesday, May 31, 2006

Andrés,

Yes, I tried that as well.  Still nothing. 

I did some snooping, and for some reason the CurrencyManager for the ErrorProvider has suspended binding, although I'm not sure why.

The binding works for the other controls... just not the error provider. 

Is it because I'm trying to bind the ErrorProvider to a complex object, instead of something like a string property?  MergeData.Org1 is of type OrganizationInfo.. the rule is that Org1 cannot be null.

Andy

ajj3085 replied on Wednesday, May 31, 2006

Ok,

It does seem to be something stupid.

I think I've got it to work; I bind the ErrorProvider to Org1BindingSource.  org1BindingSource.DataSource = MergeDataSource and org1bindingSource.DataMember="Org1".

The problem seems to be that I didn't have a control bound to 'Org1'.  As soon as I bind a control to Org1, it seems to show.  I guess for ErrorProvider to work for a property, that particular property actually needs to have a control which is bound to it, not just a BindingSource.

Thanks for all the suggestions, they helped me look into different things to try.

Andy


Copyright (c) Marimer LLC