IDataErrorInfo in winforms
Asked Answered
U

2

11

Can IDataError info be used properly in a winforms application? In the past I was doing my binding the usual way(1) and did the validation in the OnValidating event of the particular control. I would like to move the data validation to the domain model so that I can easily swap out user interfaces and so that all of the logic is in one place.

I was looking into IDataErrorInfo but everything I find deals with WPF and the app in development is strictly a winforms app.

I also noticed that the binding that gets used in WPF is in System.Windows.Data and the binding that I've always been using is in System.Windows.Forms (which I don't appear to have when I try to add it as a resource - I'm using 3.5).Aside from the property "ValidatesOnDataErrors" is there a difference between the two?

(1) the usual way being:

myControl.DataBindings.Add(new Binding("Text", this.domainModel, "Property"));
Ursola answered 9/9, 2009 at 20:7 Comment(0)
B
10

This works with the ErrorProvider component in Windows Forms.

For a complete, but very simple and short tutorial, see this blog post.

Blackington answered 9/9, 2009 at 20:22 Comment(3)
+1 Fantastic blog post. Cured all of my current woes. Thank you very much.Ursola
Looks like the link to the fantastic blog post is broken: making this link only answer obsolete.Ornithic
@Bjørn-RogerKringsjå It's actually not a link-only answer. The suggestion about ErrorProvider makes this an answer without the link.Dowery
E
1

Yes, IDataErrorInfo works in winforms. For example, DataGridView will use this automatically both per-row and per-cell. But it is implementation-specific, and isn't automatically applied to other bindings. I did once write some code to associate it to an error-provider and do the work via change events, but I don't have it to hand unfortunately. But I seem to recall it wasn't huge.

Elka answered 9/9, 2009 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.