PC Review


Reply
Thread Tools Rate Thread

Assigning variables using FieldInfo.SetValue

 
 
=?Utf-8?B?QnJlbnQ=?=
Guest
Posts: n/a
 
      24th Nov 2004
I have variables in a structure loaded into a list box.
I thought I could use FieldInfo.SetValue to update the items value when the
user clicks on it, but it is not working.

..
..
..
Dim fi As Reflection.FieldInfo
fi = tp.GetField(Item)
MsgBox(fi.GetValue(InItems)) 'returns the original value
fi.SetValue(InItems, Value.ToString) 'Nothing happens
MsgBox(fi.GetValue(InItems)) 'still returns the original value
..
..
..

Am I missing something or doing it wrong?

Thanks
Brent

 
Reply With Quote
 
 
 
 
Imran Koradia
Guest
Posts: n/a
 
      24th Nov 2004
You might want to read up on this thread:
http://groups.google.com/groups?lr=&th=84f4322176f2d1f4

Basically, since a structure is a value type but the SetValue expects an
object, the SetValue is working on the boxed object rather than on the
structure itself. You should find a couple of solutions in the thread above
on how to work around this.

hope that helps..
Imran.


"Brent" <(E-Mail Removed)> wrote in message
news:BCD08621-52DB-4AF6-950D-(E-Mail Removed)...
> I have variables in a structure loaded into a list box.
> I thought I could use FieldInfo.SetValue to update the items value when

the
> user clicks on it, but it is not working.
>
> .
> .
> .
> Dim fi As Reflection.FieldInfo
> fi = tp.GetField(Item)
> MsgBox(fi.GetValue(InItems)) 'returns the original value
> fi.SetValue(InItems, Value.ToString) 'Nothing happens
> MsgBox(fi.GetValue(InItems)) 'still returns the original

value
> .
> .
> .
>
> Am I missing something or doing it wrong?
>
> Thanks
> Brent
>



 
Reply With Quote
 
=?Utf-8?B?QnJlbnQ=?=
Guest
Posts: n/a
 
      24th Nov 2004
Ah

So close, but so far.
I just switched out the word Structure for Class and it worked.

Thanks
Brent



"Imran Koradia" wrote:

> You might want to read up on this thread:
> http://groups.google.com/groups?lr=&th=84f4322176f2d1f4
>
> Basically, since a structure is a value type but the SetValue expects an
> object, the SetValue is working on the boxed object rather than on the
> structure itself. You should find a couple of solutions in the thread above
> on how to work around this.
>
> hope that helps..
> Imran.
>
>
> "Brent" <(E-Mail Removed)> wrote in message
> news:BCD08621-52DB-4AF6-950D-(E-Mail Removed)...
> > I have variables in a structure loaded into a list box.
> > I thought I could use FieldInfo.SetValue to update the items value when

> the
> > user clicks on it, but it is not working.
> >
> > .
> > .
> > .
> > Dim fi As Reflection.FieldInfo
> > fi = tp.GetField(Item)
> > MsgBox(fi.GetValue(InItems)) 'returns the original value
> > fi.SetValue(InItems, Value.ToString) 'Nothing happens
> > MsgBox(fi.GetValue(InItems)) 'still returns the original

> value
> > .
> > .
> > .
> >
> > Am I missing something or doing it wrong?
> >
> > Thanks
> > Brent
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FieldInfo.SetValue on nested types Mark D. (GY) Microsoft C# .NET 3 12th Jul 2008 09:36 AM
Anyone experienced with FieldInfo.SetValue jw56578@gmail.com Microsoft VB .NET 1 11th May 2005 03:59 AM
FieldInfo Class - SetValue Member Method =?Utf-8?B?RGVubmlz?= Microsoft VB .NET 5 22nd Dec 2004 06:34 PM
FieldInfo.SetValue failing under VB.Net 2003 Laurie Microsoft VB .NET 2 14th Nov 2004 09:46 PM
FieldInfo.SetValue() =?Utf-8?B?R2xlbg==?= Microsoft C# .NET 3 18th Jun 2004 09:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.