Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating An Inheritance with Multiple Enums

Status
Not open for further replies.

mbde

Programmer
Mar 14, 2005
55
0
0
US

I am in the process of creating many custom controls, each with a grid control in it (the Complete Grid Control)

I wanted to try and make all of these grid controls inherit from some base control so that code does not have to be duplicated and every control follows the same standard

So I have properties
DataSource
And
CheckedCollection as each grid will have checkboxes and to return the records the user selected


I have method
BindData which users of the control can call to performs the internal control databind

The Abstract Base Class will have to be of T so that DataSource and Check Collection can return List<T>

The part where I am stuck is I have a SetVisible method which takes in an Enum Flag and a bool. So currently for a grid I have

public enum GridColumnsFlags
{
CheckBox = 1,
StartDate = 2,
Product = 4,
SalesPerson = 8,
Status = 16,
All = 31
}
private enum GridColumns
{
CheckBox = 1,
StartDate,
Product,
SalesPerson,
Status
}

Then a call would be like
SetVisible(GridColumnsFlag.CheckBox | GridColumnsFlag.Product, true);

That works today because each grid has its own Enum. Now finally the question. I know enums can not be inherited nor put in an interface because they are a type not an object but is there a way to have the Base class refernce the parent classes enum (even if they are name the same)

So I would be able to write the code similar to

private void SetVisableProperty(GridColumnsFlags flag, bool visable)
{

if ((flag & GridColumnsFlags.CheckBox) == GridColumnsFlags.CheckBox)
{
ProductGrid.Columns[(int) GridColumns.CheckBox].Visible = visable;
}

if ((flag & GridColumnsFlags.PriceRequestId) == GridColumnsFlags.PriceRequestId)
{
ProductGrid.Columns[(int)GridColumns.PriceRequestId].Visible = visable;
}


Maybe use a loop or reflection to get the members of the enum, as the values would be different then each grid?

Hope all of this makes some sense.
 
Just to share my thoughts about your enum queries.

To get an enum contained on another class, just add the class name before the enum, because class name on this case acts like a namespace.

e.g. BaseClass.SomeEnum.SomeValue

On .NET, identical type names on different namespaces are still different types.

my 2cents [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top