473,394 Members | 1,800 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,394 software developers and data experts.

How do you use GetProperty.SetValue with the index parameter?


Hello,

I have been struggling with the SetValue method when trying to use
indexed items. I can't figure out what needs to be done to create
the "index As Object()" parameter. Juding from the lack of examples
out there on the net I am sure many people would love to see how this
mysterious parameter works in a real example. Anyone?

Thanks in advance,
Doug

Nov 21 '07 #1
5 4327
On Nov 22, 2:22 am, dig_dug_d <doug.dimic...@gmail.comwrote:
Hello,

I have been struggling with the SetValue method when trying to use
indexed items. I can't figure out what needs to be done to create
the "index As Object()" parameter. Juding from the lack of examples
out there on the net I am sure many people would love to see how this
mysterious parameter works in a real example. Anyone?

Thanks in advance,
Doug
Hi Doug,
If I am not mistaken, you must be talking with respect to
setting property values using Reflection ? If it is so, you can use
the following syntax to set a value for the property

ctl.GetType().InvokeMember(strProperty, BindingFlags.SetProperty,
Nothing, ctl, New Object() {strControlResource})

I will explain you all the things in this statement.

ctl - Control object. You can replace this with whatever you want, but
having the GetType() method.
InvokeMember is called to set a named property to some value provided.
strProperty - Name of the property to be set. For example - Text
BindingFlags.SetProperty denotes that we need to set the property.
the last parameter is of special interest now, since it is the actual
value that would be set to the property. Here I have created an Object
array on fly containing the only item strControlResource.

Hope this helps.
If I have misunderstood your question please revert back with relevant
details, so that I may help you.
Thanks,
coolCoder.

------------------------------------------------------------------------------------------------------------------------------------------------
If you find this post helpful, please rate it.
Nov 22 '07 #2
dig_dug_d wrote:
I do need to use reflection.. as my controls are being created
dynamically.
You can assign an .ID to them when they are created, then use that ID to
figure out which control sent an event.

Andrew
Nov 22 '07 #3
Thanks for the reply,

I'm sorry I got this off on a tangent..the example I gave was only to
frame the question "how do use the index parameter of the SetValue
method". I appreciate the help.. but there is this crazy parameter
that no one seems to know how to use and it seems others have asked..
but I have yet to find a good example on how this aspect of the method
works. I really do appreciate all the help and time people spend
replying... and if I ever do find the answer I will most certainly
post it.

Thanks,
Doug

On Nov 22, 9:19 am, "Andrew Morton" <a...@in-press.co.uk.invalid>
wrote:
dig_dug_d wrote:
I do need to use reflection.. as my controls are being created
dynamically.

You can assign an .ID to them when they are created, then use that ID to
figure out which control sent an event.

Andrew
Nov 23 '07 #4
dig_dug_d wrote:
I do need to use reflection as my controls are being created
dynamically.
No you don't.

/If/ you know the name of a control then you can use FindControl to find
it and manipulate it.

Even if you /don't/ know the name of the control you want (and I'm
slightly puzzled as to why you wouldn't) you can iterate through the
page's Controls collection and recursively down through each "container"
control to find a control that you're interested in.

Having found one, you can /ask/ that Control what Type it is ...

If TypeOf ctl Is ListBox Then
. . .

.... and, if it's one you want, you can cast it to the correct Type and
manipulate it as required.

/None/ of the above requires Reflection.

IMHO, you must know /something/ about these controls; how can you work
with them otherwise? It's like blindfolding a Vet and asking him to
perform surgery on an unknown animal.

HTH,
Phill W.
Nov 23 '07 #5
"dig_dug_d" <do***********@gmail.comschrieb
Thanks for the reply,

I'm sorry I got this off on a tangent..the example I gave was only
to frame the question "how do use the index parameter of the
SetValue method". I appreciate the help.. but there is this crazy
parameter that no one seems to know how to use and it seems others
have asked.. but I have yet to find a good example on how this
aspect of the method works. I really do appreciate all the help and
time people spend replying... and if I ever do find the answer I
will most certainly post it.

I don't find a Selected property with the Listbox control, neither Winforms,
nor Webforms.

I fail to see the problem. Indexed properties are properties with arguments,
for example

o.p(17) = 12

or

o.p(17, 24) = 12
So:

Private Class C
Public Property P(_
ByVal arg1 As Integer, ByVal arg2 As Integer) As Integer
Get

End Get
Set(ByVal value As Integer)
MsgBox(arg1 & " " & arg2)
End Set
End Property
End Class

Usage:
Dim o As New C
Dim Args(1) As Object

Args(0) = 17
Args(1) = 24

o.GetType.GetProperty("P").SetValue(o, 17, Args)

Armin

Nov 23 '07 #6

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

Similar topics

3
by: Glen | last post by:
FieldInfo.SetValue() doesn't appear to work when trying to set the values of fields of a struct. Why? Because structs are passed by value and not reference? -- Thanks, Glen
0
by: Rick Strahl [MVP] | last post by:
A while back I've built a bunch of generic Reflection routines that simplify the process of access properties/fields and methods a bit easier by creating wrappers around Property/Field/Method info...
6
by: ORC | last post by:
I will use FieldInfo to import values from a XML file into the fields of an objects. But how to convert to the proper type like in this: public void Load(object MyClass) { foreach( FieldInfo...
0
by: Johan | last post by:
I am trying to set the property of a custom class that has a property that expects a parameter. How can I use the setvalue of the property info to set a property value by using a parameter as...
2
by: JC Voon | last post by:
Hi: How to use GetProperty to return the TextBox.Font.Name property ? Dim propInfo As PropertyInfo = ctrl.GetType.GetProperty("Font", BindingFlags.Public Or BindingFlags.NonPublic Or...
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
1
by: Judy K | last post by:
Greetings all, I am new to Java, JSP and javascripting. I was passing parameters in a query string and have learned the dangers therein, so am now trying to pass a parameter as a javabean property...
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)...
3
Fr33dan
by: Fr33dan | last post by:
I'm having trouble getting the Type.GetProperty(string) method to return the property that I need. Whenever I call it all I get is a null value even thought the type that i'm calling does contain the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.