473,326 Members | 2,111 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,326 software developers and data experts.

PropertyInfo.GetValue - Problems with Count Property ofType ArrayList

gt
I am trying to replicate the functionality of
DataTextField/DataValueFields in an extended DropDownList control that
I have created in order to provide a third value for each ListItem.
This value will be stored in a client-side array currently as that is
where it is required. Now to the problem.

I've overriden the DataBind Method of my DropDownList and within it
have added the code below:

Type DataSourceType = this.DataSource.GetType();
PropertyInfo LengthProperty = DataSourceType.GetProperty( "Count" );
MethodInfo get_ItemMethod = DataSourceType.GetMethod( "get_Item" );

if( LengthProperty != null && get_ItemMethod != null )
{

for( int i = 0; i < Convert.ToInt32( LengthProperty.GetValue(
DataSource, null) ); i++ )
{
object[] Parameters = new object[
get_ItemMethod.GetParameters().Length ];
Parameters[0] = i;
object CurrentObject = get_ItemMethod.Invoke( DataSource,
Parameters );
}
}

Now When I execute this code in debug mode, and break the Statement
LengthProperty.GetValue( DataSource, null) gives me an error in the
Watcher of
'error: arguments do not match parameters for function
'LengthProperty.GetValue''

Can anyone see where I may be going wrong here?
Nov 16 '05 #1
1 7382
gt <de*@thehexx.com> wrote:
I am trying to replicate the functionality of
DataTextField/DataValueFields in an extended DropDownList control that
I have created in order to provide a third value for each ListItem.
This value will be stored in a client-side array currently as that is
where it is required. Now to the problem.
<snip>

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
By the way:
for( int i = 0; i < Convert.ToInt32( LengthProperty.GetValue(
DataSource, null) ); i++ )


That's pretty nastily inefficient - you'll be retrieving the property
by reflection on every iteration of the loop.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

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

Similar topics

3
by: Oskar Lundgren | last post by:
I want to iterate over fields declared like this, using reflection (and there are good reasons for that): Protected WithEvents Foo1 As Bar Protected WithEvents Foo2 As Bar .... I use the...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
0
by: ENathan | last post by:
I've created a web app named "OnePage" and it has only one page, WebForm1. I added a web control, TextBox1 and set the Text property of TextBox1 equal to "Text from TextBox1". I've built the...
0
by: SyZLaB | last post by:
I had a problem using system.reflection.propertyinfo.getvalue in vb - and searched a lots of newsgroups and libraries - but none had the solution to my problem - and it also seamed like many others...
2
by: Carlos Rodriguez | last post by:
I have the following function in C#public void Undo(IDesignerHost host) { if (!this.componentName.Equals(string.Empty) && (this.member != null)) { IContainer container1 = (IContainer)...
1
by: Marius Horak | last post by:
The weekend is coming so you will have plenty of time to find the right answer. I did search the Net but could not find anything useful. I have no problems with GetValue(obj, null) for a simple...
7
by: Tom Dacon | last post by:
I'm using Reflection to iterate over the properties and fields of an arbitrary object. For non-indexed properties it's pi.GetValue(theObject, Nothing) for VB, or pi.GetValue(theObject, null) for...
1
by: samueltilden | last post by:
I am writing a very generic DumpObject(object Obj) method. I can easily GetType() and GetType().GetProperties(). I can easily PropertyInfo.GetValue(Obj, null) for scalar variables. The...
1
by: damiensawyer | last post by:
Hi, I need to invoke .getvalue and .setvalue on fieldinfo and propetyinfo objects. Even though they're both derived from MemberInfo, they don't share those two methods. I've finding myself...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.