type.Attributes names

B

bstieve

Hi all,

i'm looking at the next problem.
i'm trying to get the names of attributes of object or of types.

example
class test
private name as string
sub new (byval test as string)
me.name = test
end sub
end class

class main
dim x as new test("hello")
end class

i now would like tto know how i can get from either the type of test
or the object the value name. i do not want the data in the attributes
but the defined name of the attributes

many thanks in advance,
Stieve
 
A

Armin Zingler

Hi all,

i'm looking at the next problem.
i'm trying to get the names of attributes of object or of types.

example
class test
private name as string
sub new (byval test as string)
me.name = test
end sub
end class

class main
dim x as new test("hello")
end class

i now would like tto know how i can get from either the type of test
or the object the value name. i do not want the data in the
attributes but the defined name of the attributes

I've tried to understand what you are trying to achieve but I failed.
Could you please describe the result expected?

About attributes:
http://msdn2.microsoft.com/en-us/library/5x6cd29c.aspx
http://msdn2.microsoft.com/en-us/library/39967861.aspx


Armin
 
S

Stieve

my final goal is to create a dynamic listview.
i would like to create a user controle where i send a collection of
unique typed objects to and it populates the listview dynamical.
i want it to use the names of the attributes of the objects as columns
and then populate it with the values in attribute.

stieve
 
A

Armin Zingler

Stieve said:
my final goal is to create a dynamic listview.
i would like to create a user controle where i send a collection of
unique typed objects to and it populates the listview dynamical. i
want it to use the names of the attributes of the objects as columns
and then populate it with the values in attribute.

I feel sorry, I don't see any attributes in your code.


Armin
 
T

Tom Shelton

Hi all,

i'm looking at the next problem.
i'm trying to get the names of attributes of object or of types.

example
class test
private name as string
sub new (byval test as string)
me.name = test
end sub
end class

class main
dim x as new test("hello")
end class

i now would like tto know how i can get from either the type of test
or the object the value name. i do not want the data in the attributes
but the defined name of the attributes

many thanks in advance,
Stieve

What do you mean by attributes? I don't see any attributes in your
code? Are you talking about properties? Either way, you'll probably
want to explore the System.Reflection namespace.
 
L

Lloyd Sheen

Stieve said:
my final goal is to create a dynamic listview.
i would like to create a user controle where i send a collection of
unique typed objects to and it populates the listview dynamical.
i want it to use the names of the attributes of the objects as columns
and then populate it with the values in attribute.

stieve

I have done something like you want. You are mixing the terms though.
Objects have properties and those properties can have attributes.

You will need to use reflection to get a list of the properties of the
object. From that collection you can dynamically create your columns. You
will then need to map the column to the property as you populate the
listview.

You can use attributes to indicate whether or not to use a certain property
as a column. The best example of this are the attributes used to control
the property grid. There are attributes used to indicated the Catagory of
the property and whether or not to show the property on the property grid.

There is alot of research that goes into what you are doing but it can be
done.

Google: Reflection - to get property list
Attributes or Property Grid to see how you use attributes to
control visibility.

Hope this helps
Lloyd Sheen
 
K

kimiraikkonen

What do you mean by attributes?  I don't see any attributes in your
code?  Are you talking about properties?  Either way, you'll probably
want to explore the System.Reflection namespace.

I agree, i think he means name property of the objects.
 
P

Phill W.

Stieve said:
my final goal is to create a dynamic listview.
i would like to create a user controle where i send a collection of
unique typed objects to and it populates the listview dynamical.
i want it to use the names of the attributes of the objects as columns
and then populate it with the values in attribute.

An alternative for you:

To each class that you want to display in this way, add a method that
"renders" your class into a given ListView.
For consistency, you probably want to do this with an Interface.

Interface ICanBeListViewed
Function GetColumns() As String()
Sub Render( lvDisplay as ListView )
End Interface

Class X
Implements ICanBeListViewed

Function GetColumns() As String()
' Return an array of column names
Return New String() { "a", "b" }
End Function

Sub Render( lvDisplay as ListView ) _
Implements ICanBeListViewed.Render

' In here, add an Item and Subitems into the given ListView
With lvDisplay.Items.Add( "a value" )
.SubItems.Add( "b value" ) ' (I think)
End With
End Sub

End Class

Now, to load the ListView, you create Columns based on the GetColumns()
value of one of the items in your collection, then Render() each object
into the ListView.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top