473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

GetProperties

I am trying to get the properties of a DataTable or DataView using the
following code where obj is an object set to either a DataTable or DataView:

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston
Nov 21 '05 #1
6 2711
Dennis,

I was looking at your problem and had some questions however it is for you
nigth when it is for me day. Than I looked what you was really doing and
thought that it could be done more simple.

This was what I made
\\\
Dim myarraylist As New ArrayList
if TypeOf obj Is DataView Then
For Each col As DataColumn In _
DirectCast(obj, DataView).Table.Columns
myarraylist.Add(col.ColumnName)
Next
Else
For Each col As DataColumn In _
DirectCast(obj, DataSet).Tables(v_DataMember).Columns
myarraylist.Add(col.ColumnName)
Next
End If
///

I hope this helps

Cor

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston

Nov 21 '05 #2
Thanks Cor. That's the way I'll do it but I still wonder what's wrong with
the other code. I had gotten that technique from an article by Rockford
Lhotka on creating a Data Bound LIstView control. I had it working and then
did something stupid and couldn't get it to work again. Darn if I know what
I accidentally changed though. The code is pretty simple and works for
ArrayLists and Array's of Classes and STructures as well.

"Cor Ligthert" wrote:
Dennis,

I was looking at your problem and had some questions however it is for you
nigth when it is for me day. Than I looked what you was really doing and
thought that it could be done more simple.

This was what I made
\\\
Dim myarraylist As New ArrayList
if TypeOf obj Is DataView Then
For Each col As DataColumn In _
DirectCast(obj, DataView).Table.Columns
myarraylist.Add(col.ColumnName)
Next
Else
For Each col As DataColumn In _
DirectCast(obj, DataSet).Tables(v_DataMember).Columns
myarraylist.Add(col.ColumnName)
Next
End If
///

I hope this helps

Cor

If TypeOf obj Is DataSet Then
myDataList = CType(CType(obj, DataSet).Tables(v_DataMember), _
IListSource).GetList
ElseIf TypeOf obj Is IListSource Then
myDataList = CType(obj, IListSource).GetList
End If
Dim obj As Object = v_DataList.Item(0)
Dim props As PropertyInfo() = myDataList.GetType.GetProperties()

Dim colname as string()
Redim colname(ubound(props)
For i = 0 to ubound(props)
colname(i) = props(i).Name
Next i

I get colname array as follows:
colname(0) = "DataView"
colname(1) = "Item"
colname(2) = "Item"
colname(3) = "Row"
colname(4) = "RowVersion"
colname(5) = "IsNew"
colname(6) = "IsEdit"
Where should be getting:
colname(0) = "Column1"
colname(1) = "Column2"
........

It seemed to work once then I must have changed something because it won't
work anymore. Any suggestions?

--
Dennis in Houston


Nov 21 '05 #3
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #4
Thanks for reply. I need property/field names as well as Canread, canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes. I
had the damn code working at one time but must have messed it up and for the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #5
Dennis,

Maybe now you tell this I will try it in the weekend, not today anymore.
However my question was what type is "myDataList".

I have seen this one as well in C# code. And once did it in VBNet however I
did not save it.

No promises of course.

Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks for reply. I need property/field names as well as Canread,
canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes.
I
had the damn code working at one time but must have messed it up and for
the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of
this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)

Nov 21 '05 #6
myDataList is dimensioned as

Dim myDataList as IList

Thanks for help. Hope you can get it working.

"Cor Ligthert" wrote:
Dennis,

Maybe now you tell this I will try it in the weekend, not today anymore.
However my question was what type is "myDataList".

I have seen this one as well in C# code. And once did it in VBNet however I
did not save it.

No promises of course.

Cor

"Dennis" <De****@discussions.microsoft.com>
Thanks for reply. I need property/field names as well as Canread,
canwrite.
My routine also accepts Arraylists and Array's of Structures and Classes.
I
had the damn code working at one time but must have messed it up and for
the
life of me I can't figure it out. I know how to do it using If statements
for TypeOf for DataView's, Datatables, DatsSets, etc. but the beauty of
this
code was that it should work for any Ilist which all of these implement.

"kevin" wrote:
You are receiving the names of the properties of the DataList objject
(IListSource). Instead of attempting to get the names in this manner,
why not just use the DataView or DataTable as your source object.
Meaning - DataTable has a DefaultView Property which will allow you to
simply use only DataViews, or you can get the Source DataTable from the
DataView and use the DataTable only. Are you using any additional
properties of the IListSource Interface, or do you only need the Column
Names?

Kevin M. Schreiner
VP Software Architecture
Business Intelligence Force (bi4ce)


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Balamurukan | last post by:
hai, PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this); PropertyDescriptor myProperty = properties.Find ("Cols",false); PropertyDescriptorCollection arr=...
0
by: Adriano Coser | last post by:
Hello. I'm facing the exact problem described here:...
0
by: Adriano Coser | last post by:
Hello. I have an ExpandableObjectConverter subclass that I associate to the 'Converter' of a custom property descriptor. After I changed my .net code to the new syntax (VC 2005), the...
13
by: Bevan Arps | last post by:
I have a simple question, but one to which I haven't (after a whole bunch of Googling) been able to find an answer: Are there any guarantees to the order of PropertyInfo objects returned by a...
0
by: Nebelung | last post by:
Hi! I've written a custom ExpandableObjectConverter in which I have overridden GetPropertiesSupported and GetProperties (and some more). By setting breakpoints in all methods I have found out...
0
by: Nebelung | last post by:
Hi! I've written a custom ExpandableObjectConverter in which I have overridden GetPropertiesSupported and GetProperties (and some more). The class to which this TypeConverter is applied has all...
0
by: Nebelung | last post by:
In a custom ExpandableObjectConverter I have overridden GetPropertiesSupported (always returns true) and GetProperties. The class to which this TypeConverter is applied has only public properties...
9
by: Patrick | last post by:
Hello All, Does anyone know what order GetProperties() returns public properties in? I'm using custom Attributes on the properties of my Business objects (NHibernate) to let me know if they should...
6
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.