JDYoder Posted August 1, 2005 Posted August 1, 2005 On a custom control in design mode, I have a drop-down property based on an enum. Now on my control's property grid, I want a second drop-down property based of another enum, but it would change to a different enum list based on the value selected in the first drop-drop box. For example... Public Enum A F1 F2 End Enum Public Enum B G1 G2 G3 G4 G5 End Enum Public Enum C V1 V2 V3 End Enum Property1 is always assigned to Enum A. No problem there. However, I want Property2 to use Enum B if Property1 = "F1", but to use Enum C if Property1 = "F2". Is this possible? Quote
rot13 Posted August 1, 2005 Posted August 1, 2005 That is a very interesting problem... At first I was thinking "that's easy... you can just..." then realized I didn't know how to do it. I will search and see if I can come up with something for you. :) Quote
JDYoder Posted August 1, 2005 Author Posted August 1, 2005 That'd be great... best of luck to you as I couldn't find anything. Quote
Joe Mamma Posted August 1, 2005 Posted August 1, 2005 Back up for a second - What you are asking to do is: Change the type of a property depending on the value of another property? Now think about it for a second. Does that sound reasonable? That's like saying - when I am in North America, HairColor reflects the color of my hair, else it reflects my religion. I am betting your object model is underdefined. Why don't you have a base abstract control that implements 90% of your functionality, then make concrete control that have the particular enum published out? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
bri189a Posted August 2, 2005 Posted August 2, 2005 That gets back to our post the other day...VB has a stigma about it for a reason. I myself don't see why'd you'd concrete a list values that way...if there's even a 1% remote chance that a value will be added, it's in a datasource for me...but that's me, I like low coupling. Quote
JDYoder Posted August 2, 2005 Author Posted August 2, 2005 Quote Change the type of a property depending on the value of another property? Now think about it for a second. Does that sound reasonable? Sure it does. Overloading in VB.Net allows you to do that all the time by passing different parameters to the same named function, which can have a different return type. Do you know about overloading? Quote That's like saying - when I am in North America' date=' HairColor reflects the color of my hair, else it reflects my religion.[/quote'] Poor analogy that doesn't even make sense. Anyway, the first enum basically serves as a pseudo-filter to the second one. Example off the top of my head: Rather than have a property called "Animal" that lists 100 animals, I'm wondering if I can instead have a property that lists "Species". Then depending on what I pick ("Mammal", "Reptile", etc.) it limits what I can pick in the second property by returning a different enum. If it's not possible, then fine. But I'm just asking if it's possible. Quote
IngisKahn Posted August 2, 2005 Posted August 2, 2005 It is certainly possible (some hardcore use of System.Reflection would be my first guess) but it is far from practical. The type of relationship you're talking about is best represented thru use of class inheritance, not thru enums. Quote "Who is John Galt?"
JDYoder Posted August 2, 2005 Author Posted August 2, 2005 Quote The type of relationship you're talking about is best represented thru use of class inheritance' date=' not thru enums.[/quote'] I agree, but if you want a property to have a drop-down list, you have to use an enum, don't you? Quote
Joe Mamma Posted August 2, 2005 Posted August 2, 2005 (edited) Quote Example off the top of my head: Rather than have a property called "Animal" that lists 100 animals' date=' I'm wondering if I can instead have a property that lists "Species". Then depending on what I pick ("Mammal", "Reptile", etc.) it limits what I can pick in the second property by returning a different enum.[/quote']And what I am saying is you wouldnt use enumerations but a class hierarchy. using your example - "Mammal" is not an enumerable property but a subtype of Animal. as are "Reptile", "Bird", etc. . . all inheriting from animal. you can always use the 'is' operator (C# . . . in VB use the typeof [object] is [type]) to determine the sub class. Also my anology is absolutely correct!!! I am, contrary to widely held opinion, a homo sapiens. Homo sapiens is a concrete class extending the abstract hierarchy Homo -> Hominidae -> Primata -> Mammalia -> Chordata -> Animalia with Animalia being the top most abstract super class. Some enumerable properties I do have are EyeColor, HairColor - but these are properties specified within the superclass Mammalia. At the Homo Sapiens specification, you have some possibly enumerable properties such as Religion, EducationLevel, SalaryLevel, etc. . . Again, what you are proposing is, If you set my Religion to "DevoutDeconstructionist", EducationLevel refers to my BloodType, otherwise it actually refers to my EducationLevel. And you're right, that doesnt make sense. . . but that is what you are proposing! As a rule, if we find that what we want to do can't be done, then most likely our analysis is flawed. What are you trying to model???? Edited August 2, 2005 by Joe Mamma Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted August 2, 2005 Posted August 2, 2005 (edited) Quote I agree' date=' but if you want a property to have a drop-down list, you have to use an enum, don't you?[/quote']how many determining enums do you have??? given the following: enum Determinant enumSet1, enumset2 end enum enum Set1 Set1Item1, Set1Item2, end enum enum Set1 Set2Item1, Set2tem2, end enum you want a Determinant property to specify what is available in some other property. . . right? I am saying no, this calls for a class hierarchy: [/font] [font=Courier New][b][color=blue]public MustInherit class[/color][/b] Determinant[/font] [font=Courier New]' 95 % of your code is here [/font] [font=Courier New][color=blue][b]end class[/b][/color][/font] [font=Courier New][/font] [font=Courier New][b][color=blue][/b] [b][font=Courier New][b][color=blue]public class[/color][/b] [color=black]Set1Class[/color] [/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]inherits[/b][/color] [color=black]Determinant[/color][/font] [font=Courier New][color=blue][b]private[/b][/color] [color=black]aSet[/color] [b]as[/b] [color=black]Set1[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]public property[/b][/color] [color=black]Set[/color]() [b]as[/b] [color=black]Set1[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]get[/b][/color][/font] [font=Courier New][font=Verdana] [/font][b]return[/b] [color=black]aSet[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end get[/b][/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]set[/b][/color] ([b]Value[/b] [b]as[/b] [color=black]Set1[/color][/font] [font=Courier New][font=Verdana] [/font][color=black]aSet[/color] [b]=[/b] [b]Value[/b][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end set[/b][/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end property[/b][/color][/font] [font=Courier New][color=blue][b]end class[/b][/color][/font] [/color][/b][/font] [font=Courier New][font=Courier New][/font][/font] [font=Courier New][font=Courier New][b][color=blue][font=Courier New][b][color=blue][font=Courier New][b][color=blue]public class[/color][/b] [color=black]Set2Class[/color] [/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]inherits[/b][/color] [color=black]Determinant[/color][/font] [font=Courier New][color=blue][b]private[/b][/color] [color=black]aSet[/color] [b]as[/b] [color=black]Set2[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]public property[/b][/color] [color=black]Set[/color]() [b]as[/b] [color=black]Set2[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]get[/b][/color][/font] [font=Courier New][font=Verdana] [/font][b]return[/b] [color=black]aSet[/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end get[/b][/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]set[/b][/color] ([b]Value[/b] [b]as[/b] [color=black]Set2[/color])[/font] [font=Courier New][font=Verdana] [/font][color=black]aSet[/color] [b]=[/b] [b]Value[/b][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end set[/b][/color][/font] [font=Courier New][color=blue][font=Verdana][color=#000000] [/color][/font][b]end property[/b][/color][/font] [font=Courier New][color=blue][b]end class [/b][color=black][/color][/color] [/color][/b][/font][/color][/b][/font][/font] thus eliminating the need for the determinant enum. instead of selecting a value for the determinant from the drop down, just drop the control of the specific subtype on the form. Make sense???? Edited August 2, 2005 by Joe Mamma Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
JDYoder Posted August 4, 2005 Author Posted August 4, 2005 I guess it doesn't make sense to me, but that's all right. You and others don't need to waste anymore time with it. I'll just assume it can't be done. Thanks for your time. Quote
Joe Mamma Posted August 4, 2005 Posted August 4, 2005 Quote I guess it doesn't make sense to me' date=' but that's all right. You and others don't need to waste anymore time with it.[/quote']Dont give up!!! You act as if I actually have a life. :) Quote I'll just assume it can't be done. Thanks for your time.What you want to do is most likely possible, just not the way you are trying to do it. What are you trying to model???? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
JDYoder Posted August 4, 2005 Author Posted August 4, 2005 We're batting around ideas in our development group to deal with all these literal strings for Tables, Fields, and Procedures that we have floating around in our code. Since we have a lot of programmers dealing with various parts (of a very large program) we're finding we have misspellings and items that simply don't exist anymore. So we're considering creating enumerations that to include all our Tables, Fields, and Procedures. We would generate these enums wherever a change is made to the DB. That way, any missing or changed literals would be flagged and we could easily correct them. We have a custom made textbox, each of which stores the table and field it should point to. (Again, as a literal string. When I learned of this recently, I saw trouble on the horizon.) So I was thinking we could use enums to prevent misspellings, etc. Now to list all our tables (dozens) and all uniquely named fields (100's) is easy, but seemed very inefficient. So I was wondering if we could have the enum of Fields in our Fields property change, based on the Table enum selected in the Tables field, to only those fields within that Table. Fire away. :D Quote
Joe Mamma Posted August 4, 2005 Posted August 4, 2005 Quote We have a custom made textbox, each of which stores the table and field it should point to. (Again, as a literal string. When I learned of this recently, I saw trouble on the horizon.) So I was thinking we could use enums to prevent misspellings, etc. Now to list all our tables (dozens) and all uniquely named fields (100's) is easy, but seemed very inefficient. So I was wondering if we could have the enum of Fields in our Fields property change, based on the Table enum selected in the Tables field, to only those fields within that Table. Fire away. :DAhhh. . . gotcha. give me a moment. . . MS SQL server? or database agnostic??? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
JDYoder Posted August 4, 2005 Author Posted August 4, 2005 PostgreSQL Just kidding... SQL Server. :) Quote
JDYoder Posted August 4, 2005 Author Posted August 4, 2005 FYI, we have the queries and code to generate the enums. That's not an issue. Just the structure to have nested enums (or whatever) is the issue. Thanks, but don't work too hard on it if it just isn't feasible or practical. Quote
Joe Mamma Posted August 4, 2005 Posted August 4, 2005 this CustomGrid will probably give you some ideas. . . Imports System.Data.OleDb Public Class SchemaGrid Inherits System.Windows.Forms.DataGrid Private mConnection As OleDbConnection Private mSchemaId As SchemaId Private mSchemaTable As DataTable #Region " Component Designer generated code " Public Sub New(ByVal Container As System.ComponentModel.IContainer) MyClass.New() 'Required for Windows.Forms Class Composition Designer support Container.Add(Me) End Sub Public Sub New() MyBase.New() 'This call is required by the Component Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Component overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Component Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container End Sub #End Region #Region "SchemaID translation" Private ReadOnly Property SchemaGuid() As Guid Get Select Case mSchemaId Case SchemaId.Tables_Info Return OleDbSchemaGuid.Tables_Info Case SchemaId.Trustee Return OleDbSchemaGuid.Trustee Case SchemaId.Assertions Return OleDbSchemaGuid.Assertions Case SchemaId.Catalogs Return OleDbSchemaGuid.Catalogs Case SchemaId.Character_Sets Return OleDbSchemaGuid.Character_Sets Case SchemaId.Collations Return OleDbSchemaGuid.Collations Case SchemaId.Columns Return OleDbSchemaGuid.Columns Case SchemaId.Check_Constraints Return OleDbSchemaGuid.Check_Constraints Case SchemaId.Constraint_Column_Usage Return OleDbSchemaGuid.Constraint_Column_Usage Case SchemaId.Constraint_Table_Usage Return OleDbSchemaGuid.Constraint_Table_Usage Case SchemaId.Key_Column_Usage Return OleDbSchemaGuid.Key_Column_Usage Case SchemaId.Referential_Constraints Return OleDbSchemaGuid.Referential_Constraints Case SchemaId.Table_Constraints Return OleDbSchemaGuid.Table_Constraints Case SchemaId.Column_Domain_Usage Return OleDbSchemaGuid.Column_Domain_Usage Case SchemaId.Indexes Return OleDbSchemaGuid.Indexes Case SchemaId.Column_Privileges Return OleDbSchemaGuid.Column_Privileges Case SchemaId.Table_Privileges Return OleDbSchemaGuid.Table_Privileges Case SchemaId.Usage_Privileges Return OleDbSchemaGuid.Usage_Privileges Case SchemaId.Procedures Return OleDbSchemaGuid.Procedures Case SchemaId.Schemata Return OleDbSchemaGuid.Schemata Case SchemaId.Sql_Languages Return OleDbSchemaGuid.Sql_Languages Case SchemaId.Statistics Return OleDbSchemaGuid.Statistics Case SchemaId.Tables Return OleDbSchemaGuid.Tables Case SchemaId.Translations Return OleDbSchemaGuid.Translations Case SchemaId.Provider_Types Return OleDbSchemaGuid.Provider_Types Case SchemaId.Views Return OleDbSchemaGuid.Views Case SchemaId.View_Column_Usage Return OleDbSchemaGuid.View_Column_Usage Case SchemaId.View_Table_Usage Return OleDbSchemaGuid.View_Table_Usage Case SchemaId.Procedure_Parameters Return OleDbSchemaGuid.Procedure_Parameters Case SchemaId.Foreign_Keys Return OleDbSchemaGuid.Foreign_Keys Case SchemaId.Primary_Keys Return OleDbSchemaGuid.Primary_Keys Case SchemaId.Procedure_Columns Return OleDbSchemaGuid.Procedure_Columns Case SchemaId.Table_Statistics Return OleDbSchemaGuid.Table_Statistics Case SchemaId.Check_Constraints_By_Table Return OleDbSchemaGuid.Check_Constraints_By_Table Case SchemaId.DbInfoLiterals Return OleDbSchemaGuid.DbInfoLiterals End Select End Get End Property #End Region Public Property Connection() As OleDbConnection Get Return mConnection End Get Set(ByVal Value As OleDbConnection) If mConnection Is Value Then Return mConnection = Value RefreshSchemaDS() End Set End Property Public Property Schema() As SchemaId Get Return mSchemaId End Get Set(ByVal Value As SchemaId) If (mSchemaId = Value) And (Not (mSchemaTable Is Nothing)) Then Return mSchemaId = Value RefreshSchemaDS() End Set End Property Private Sub RefreshSchemaDS() If Me.DesignMode Then Return If (mConnection Is Nothing) Then mSchemaTable = Nothing Me.DataSource = Nothing Else Dim wasOpen As Boolean = mConnection.State = ConnectionState.Open If Not wasOpen Then mConnection.Open() mSchemaTable = mConnection.GetOleDbSchemaTable(SchemaGuid, Nothing) Me.DataSource = mSchemaTable If Not wasOpen Then mConnection.Close() End If End Sub End Class Public Enum SchemaId Tables_Info Trustee Assertions Catalogs Character_Sets Collations Columns Check_Constraints Constraint_Column_Usage Constraint_Table_Usage Key_Column_Usage Referential_Constraints Table_Constraints Column_Domain_Usage Indexes Column_Privileges Table_Privileges Usage_Privileges Procedures Schemata Sql_Languages Statistics Tables Translations Provider_Types Views View_Column_Usage View_Table_Usage Procedure_Parameters Foreign_Keys Primary_Keys Procedure_Columns Table_Statistics Check_Constraints_By_Table DbInfoLiterals End Enum Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
JDYoder Posted August 4, 2005 Author Posted August 4, 2005 Cool. I'll have to check that out in detail. Thanks for your help. :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.