473,662 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you use GetProperty.Set Value 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 4336
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().I nvokeMember(str Property, BindingFlags.Se tProperty,
Nothing, ctl, New Object() {strControlReso urce})

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.Se tProperty 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 strControlResou rce.

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.inv alid>
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.comschrie b
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.GetPr operty("P").Set Value(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
14437
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
1341
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 members. For example: public const BindingFlags MemberAccess = BindingFlags.Public | BindingFlags.NonPublic |
6
5812
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 field in MyClass.GetType().GetFields() ) { field.SetValue(MyClass, String_From_XML_Representing_The_Field_Value); }
0
918
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 well? Thx in advance
2
1664
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 BindingFlags.Static Or BindingFlags.Instance Or BindingFlags.IgnoreCase) will return the Font property, how to reference the Name property in then propInfo ?
15
11186
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
4399
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 instead. I see many tutorials where jsp:setProperty and jsp:getProperty are used, and they make sense. I can get them to work if I do the basic "Hello world + input" type of page. But what I need to do is get the property and assign that...
2
2512
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) host.GetService(typeof(IContainer)); IComponent component1 = container1.Components; PropertyInfo info1 = component1.GetType().GetProperty(this.member.Name);
3
10818
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 property. By adding a watch I also noticed that the Type.GetProperties() method is always returning an empty array. Am I using the method incorrectly or am I using the wrong method? if (type.Namespace == "ATE.Config") { PropertyInfo t =...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.