avoid use of typeOf to known a class from a base class variable


Author
Message
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
How can I avoid to use typeOf when I have some classes that inherit from a base class and I have to compare what type of class the variable is



in the following code:



If TypeOf MainView Is Dx.DxGridView Then

With CType(MainView, Dx.DxGridView)

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With

ElseIf TypeOf MainView Is Dx.DxCardView Then 'DevExpress.XtraGrid.Views.Grid.GridView Then

With CType(MainView, Dx.DxCardView)

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With

End If





to something like:

With CType(MainView, ThetypeOf(MainView))

.Columns(dc.ColumnName).DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric

.Columns(dc.ColumnName).DisplayFormat.FormatString = "$ #,0.00"

End With



MainView is a generic Class (devExpress BaseView) and I want to set a column property, but the generic class don't have a "column" and I have to use a ctype, I like to use a ctype (or something else) on the same object to know his type

I say, if mainview is a "cardview" or "gridView" when I put ctype(mainview,somefunctionthatgivemethetype(mainview).column work



the same to use with ctype(businesslayerVariable,getmyowntype(businesslayerVariable)).someproperty and ctype(businesslayerVariable,getmyowntype(businesslayerVariable)) give me myBO type



it is posible? thanks!



sorry if I cannot write my question correctly, I speak in spanish and it's hard to me Ermm
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search