c# - utility class vs subclassing .net controls -


I want to reuse some code that I wrote to add some functionality to a datagrid view. I want to highlight the default datagridview properties and events, so I did not want to create a new custom component, so I tried to write a subclass, which works fine. But it also happened to me that I can write a standalone utility class which takes the grid viewer in the manufacturer and sets it in the same way. E.g.

  Public category MyGrid {Private DataGridView m_dg; Public MyGrid (Datagram View DG) {m_dg = dg; M_dg.RowHeadersVisible = false; M_dg.SortCompare + = New DataGridVisionSortComparEventHandler (m_dg_SortCompare); } Zero m_dg_SortCompare (Object Sender, DataGridViewSortCompareEventArgsE) {// Custom sorting here}}  

Then somewhere I will call in my app's startup

  MyGrid G1 = new migrating (Datagreat Wi1); Migrate G2 = new migrating (DataGrid View 2);  

even further. Any damage to this approach? It seems that more and more codes are going to be the same, the difference is between how you start the extended grid (drag and drop the form and leave the sub-class control, drag the plain datagrid view and call the above code )

The only disadvantage of a utility class is that you lose designer support, if you control Sub-class, so when you do it in the designer If you add, then the changes you made in the manufacturer of your heritage control will be visible in the designer. Also, if you want to add some properties to it, they will be displayed in the Properties window, which will give it even more flexibility. If the designer support does not make any difference to you, then I do not see any other drawbacks in a utility class.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -