wrote:
1) Is it 'wrong' (i.e. poor practice) to just add a System.Windows.Forms reference to a class library project?
Well, It is really easy to add a reference to System.Windows.Forms and it will not matter as such as the original windows application loads both System.Windows.Forms as well as your class library. So there is no problem in regards to the performance.
The only thing that concerns is why do we create Class Libraries. Actually we create class library to make layers between the application end and database end. Its main motive is to have independent modules to access the database which you might add in another project and directly use those functions(Code reusability). So Our motive should be to factor code in such a way that all are independent. If you add Windows.Forms in your class library it will make the class library totally dependent on the Application and it is unseparable. Thus if this is going to be your motive, I would rather add the whole class library into my forms application rather than writing out unnecessary dependent dlls.
wrote:
2) If it is wrong, what is the best object to cast a DataGridViewRowCollection to so the class library can use it?
So better approach is to expose a method, that may take a list of DataRow element. You build the Datarow from the application and pass to the function into the layer. The layer will save those into the database. Thus the presentation layer is made independent to the data layer.
wrote:
3) Is there another way, besides trial and error and experience, to discover what can and cannot be cast to what?
Of course. Just inspect each object by going to the Definition into the Object Explorer. You see the class library and interface which the actual object is inherited from. You can case only those which are within the family of those interfaces.
For example you can cast
IDbConnection con = new SqlConnection();
IDbConnection con = new OleDbConnection();
as both of them are inherited from a common interface IDbConnection.
I hope you got the ideas clear.
Cheers.
Happy Learning.
:thumbsup: