Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2005, 09:19 AM
Registered User
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to arctica82
Default Problem in Code about "SetValue"

I have a problem in these codes in Vb.Net.I have saved the properties name and their value in Database and I want to set those values at RunTime.The Code is as fallows.("Me" is refering to a Form Class)(I cant initiialize those properties which they are from EnumType and they are not String or Number

dim t as type
t=me.gettype
t=GetProperty("RightToLeft").SetValue(Me,1,Nothing )
but at the last line it fires this Error"Object Type cannot be converted to Target Type"


A.G
 
Old April 15th, 2005, 02:27 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,
you should first instasiate your object,
then use reflection for getting proper values,
I didn't get exactly what you wanted,so have a look at this example..
Code:
            Type type=typeof(System.Data.DataTable);
            object o=System.Activator.CreateInstance(type);
            System.Reflection.PropertyInfo pf=type.GetProperty("TableName");
            pf.SetValue(o,"NewName",null);
            object s=pf.GetValue(o,null);
            textBox1.Text=s.ToString();
            as you see I make a DataTable (object o=System.Activator.CreateInstance(type);) then i.e I wanted its TableName property so I wrote System.Reflection.PropertyInfo pf=type.GetProperty("TableName");...and set and get that property at runtime
sorry I don't know VB.NET that much,send feedback if you have any problem

_____________
Mehdi.
software student.
 
Old April 15th, 2005, 03:39 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

instead of
t=GetProperty("RightToLeft").SetValue(Me,1,Nothing )
you should have written,
t.GetProperty("RightToLeft").SetValue(Me,1,Nothing )

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error when updating data (setvalue) darrenb Access VBA 3 May 3rd, 2007 09:14 PM
SetValue doesn't work with DateTimePicker Infinity VB Components 0 January 4th, 2007 03:05 AM
Code behind problem.. shabirmaher General .NET 1 August 12th, 2005 03:09 AM
Problem with Reflection.FieldInfo.SetValue method jaucourt Pro VB.NET 2002/2003 0 December 2nd, 2004 01:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.