PawanS
PawanS

Reputation: 7193

should I send win form control as parameter?

A winform forms.cs contains a gridview. This gridview(many columns) get populated with an xml elements and its attributes.

Another class "XMLReader.cs" that reads XML file and returns

List <someclassObjects>

Now I am sending gridview as a parameter from form.cs to another class "UpdateAppUI.cs" that receives the Gridview as parameter and update it.

Question is: Is there any issues with passing controls as parameter? Experienced professionals said donnnn't pass controls.

Then How I can access form controls to other classes?

What is the solution for above situation?

Upvotes: 0

Views: 664

Answers (2)

Bhavik Goyal
Bhavik Goyal

Reputation: 2796

why you want to pass the grid view?

If simply you want to update it in UpdateAppUI.cs file then pass the datafrom gridview in the datatable. And from datatable you can update the database from the class.

No need to pass the control.

If you really want to pass the datagrid then create new object of datagrid as same as yours and pass that as an parameter.

Upvotes: 1

Filip Ekberg
Filip Ekberg

Reputation: 36287

I think that what those developers are refering to is: avoid making your UI unrepsonsive. You might want to look at your design ( read: conceptual model / design diagram ) before your deside how to implement this functionality.

There's an article on MSDN covering "Give .NET Apps a Fast and Responsive UI with Multiple Threads".

Consider this, if you have a Parent form that needs to update its child controls you might want to make the whole form accessable by the "update helper". But then again, try not to make to much heavy lifting on the UI Thread.

Also remember that your controls are Objects and when Objects are passed as parameters they are sent as reference types so another "danger" is that your method might do something malicious to your control.

To make the design understandable and manageable by others as well, I would step back one step and think about the design of your software.

Upvotes: 0

Related Questions