By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,191 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,191 IT Pros & Developers. It's quick & easy.

Assigning variables using FieldInfo.SetValue

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <Br***@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
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

Nov 21 '05 #2

P: n/a
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" <Br***@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
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


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.