I have the code you see below. As such VS defines my two lists in FormMain.cs.design
like this: DRT_Tvw_TableList drt_Tvw_TableList;
and DRT_Tvw_TableList_Filtered drt_Tvw_TableList_Filtered;
To allow me to leverage inheritence in my code, I want to instead define them like this: DRT_Tvw_Abstract drt_Tvw_TableList;
and DRT_Tvw_Abstract drt_Tvw_TableList_Filtered;
So far, all I've been able to do is manually edit the FormMain.cs.design
. Is there a way to force VS
to use DRT_Tvw_Abstract
to define my two treeviews in FormMain.cs.design
, e.g., make the abstract class
appear in the toolbox
so I can drop it onto my form?
public abstract class DRT_Tvw_Abstract : TreeView
{
public DRT_Tvw_Abstract() : base()
{
}
}
public class DRT_Tvw_TableList_Unfiltered : DRT_Tvw_Abstract
{
public DRT_Tvw_TableList_Unfiltered() : base()
{
}
}
public class DRT_Tvw_TableList_Filtered : DRT_Tvw_Abstract
{
public DRT_Tvw_TableList_Filtered() : base()
{
}
}
Update
in practice, I'm using it like this (i.e., manually editing FormMain.Designer.cs
to make its code look like the following)
DRT_Tvw_Abstract drt_Tvw_TableList_Unfiltered;
DRT_Tvw_Abstract drt_Tvw_TableList_Filtered;
drt_Tvw_TableList_Unfiltered = new DRT.DRT_Tvw_TableList_Unfiltered();
drt_Tvw_TableList_Filtered = new DRT.DRT_Tvw_TableList_Filtered();
The reason I'm doing this is because there is a boatload of code that the two tree views share. Most of the code is identical for both and as such it is implemented in the abstract class. One difference between the two treeviews is that the treeviews are loaded differently:
drt_Tvw_TableList_Unfiltered is loaded from a datatable. As such, it has a
CreateTreeView(DataTable dataTable)
methoddrt_Tvw_TableList_Filtered is loaded from drt_Tvw_TableList_Unfiltered. As such, it has a
CreateTreeView(DRT_Tvw_TableList_Unfiltered drt_Tvw_TableList_Unfiltered)
method
I could implement both these in the abstract (same method name, different arguments), but I chose to implement each in the concrete class to which each belongs.
There are other differences. I deal with them either by writing custom methods in the two concrete classes or overriding abstract class abstract methods in the concrete classes
I want to make VS use the abstract class when it creates its code in FormMain.Designer.cs
so I don't have to worry about VS changing them back to the concrete class names and thereby forcing me to manually edit FormMain.Designer.cs
again and again