Assigning variables using FieldInfo.SetValue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
Ah

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

Thanks
Brent
 

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

Back
Top