Get property values from object.

Hello.
I need sample code of getting properties values of a specific object, 
please.

Thanks :) 

0
Mr
6/19/2010 1:08:14 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

4 Replies
1591 Views

Similar Articles

[PageSpeed] 28

Am 19.06.2010 15:08, schrieb Mr. X.:
> Hello.
> I need sample code of getting properties values of a specific object, 
> please.

I assume that you don't know the type of the object at design time, is that right?
Then you're looking for reflection:
http://msdn.microsoft.com/en-us/library/cxz4wk15(VS.90).aspx

See sub topic "Viewing Type Information", section "MemberInfo, MethodInfo, FieldInfo, and PropertyInfo"

-- 
Armin
0
Armin
6/19/2010 1:26:00 PM
Indeed, I am using reflection,
but for the following code, I am doing a loop, that doesn't really work :

dim c as control
dim I ,j as integer ...
Dim prs() As System.Reflection.PropertyInfo
dim propName as string
dim propValue

For i = 0 To myPanel.Controls.Count - 1
  c = myPanel.controls(I) ' one of the child controls is a dataGridView
  prs = c.getType().getProperties()
  for j = 0 to prs.count - 1
  ...
' I am looking for the published properties only.
  if prs(j).canRead and prs(j).canWrite then
 ' for the datagridview, I am getting the propety
  propName = prs(j).name
  propValue = prs(j).getValue(c, nothing) ' *** here I get sometimes an 
exception : TargetParameterCountException was unhandled. 
parameterCountMismatch

....

Why may be the reason for the exception (The control : DataGridView. 
property : Item) ?
Also, "item" is not a published property, that may seen on design time.
I want to see only properties, which are seen on design time.

Thanks :)

"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:OXJ7oM7DLHA.5724@TK2MSFTNGP05.phx.gbl...
> Am 19.06.2010 15:08, schrieb Mr. X.:
>> Hello.
>> I need sample code of getting properties values of a specific object,
>> please.
>
> I assume that you don't know the type of the object at design time, is 
> that right?
> Then you're looking for reflection:
> http://msdn.microsoft.com/en-us/library/cxz4wk15(VS.90).aspx
>
> See sub topic "Viewing Type Information", section "MemberInfo, MethodInfo, 
> FieldInfo, and PropertyInfo"
>
> -- 
> Armin 

0
Mr
6/19/2010 2:24:44 PM
Am 19.06.2010 16:24, schrieb Mr. X.:
> Indeed, I am using reflection,
> but for the following code, I am doing a loop, that doesn't really work :
> 
> dim c as control
> dim I ,j as integer ...
> Dim prs() As System.Reflection.PropertyInfo
> dim propName as string
> dim propValue
> 
> For i = 0 To myPanel.Controls.Count - 1
>   c = myPanel.controls(I) ' one of the child controls is a dataGridView
>   prs = c.getType().getProperties()
>   for j = 0 to prs.count - 1
>   ...
> ' I am looking for the published properties only.
>   if prs(j).canRead and prs(j).canWrite then
>  ' for the datagridview, I am getting the propety
>   propName = prs(j).name
>   propValue = prs(j).getValue(c, nothing) ' *** here I get sometimes an 
> exception : TargetParameterCountException was unhandled. 
> parameterCountMismatch
> 
> ....
> 
> Why may be the reason for the exception (The control : DataGridView. 
> property : Item) ?

TargetParameterCountException means that the count of the passed parameters
are incorrect. The 'Item' property requires two parameters as you can see
via intellisense, in the object browser and in the documentation. The call
would be:

   value = prs(j).GetValue(c, New Object() {param1, param2})

You'd have to pass the correct parameter types. You get the parameter information
by calling

   dim pi as parameterinfo
   pi = prs(j).GetIndexParameters(ParameterIndex)

However, if you don't know what to pass to the GetValue method, it's not possible
to get the property value.

> Also, "item" is not a published property, that may seen on design time.
> I want to see only properties, which are seen on design time.

Item is a Public property. You may want to check the custom attributes of
each property. Call prs(j).GetCustomAttributes. Then you can check the type
of each attribute, for example.

   dim prop = prs(j)
   dim atts = prop.GetCustomAttributes

   for each att in atts
       if typeof att is System.ComponentModel.DesignerSerializationVisibilityAttribute then
            dim SpecialAtt = directcast(att, System.ComponentModel.DesignerSerializationVisibilityAttribute)
            debug.print (specialatt.visibility.tostring)
       end if
   next

The DesignerSerializationVisibilityAttribute is one of the attributes attached to the DataGridView's
Item property. The other one is the System.ComponentModel.BrowsableAttribute.

Anyway, even those properties that don't have any of these attributes attached, may have multiple
parameters. If you don't know what to pass, you can only retrieve the values of those that's
GetIndexParameters method returns an empty array, i.e. with 0 items.


-- 
Armin
0
Armin
6/19/2010 6:05:15 PM
Great ... Thanks :)

I only need to search all the properties of my control (only properties 
which can be shown on the designer).
As your advise, I did getProperties & getCustomAttributes either :
prs = ... getProperties
for I = 0 to prs.count - 1
 dim prop = prs(j)
 dim atts = prop.GetCustomAttributes
 for each att in atts ... ' as your code below.

.... but I have reach the inner loop only when :specialAtt.Visibility was 
hidden.

Thanks :)

"Armin Zingler" <az.nospam@freenet.de> wrote in message 
news:OgqsHo9DLHA.5428@TK2MSFTNGP05.phx.gbl...
> Am 19.06.2010 16:24, schrieb Mr. X.:
>> Indeed, I am using reflection,
>> but for the following code, I am doing a loop, that doesn't really work :
>>
>> dim c as control
>> dim I ,j as integer ...
>> Dim prs() As System.Reflection.PropertyInfo
>> dim propName as string
>> dim propValue
>>
>> For i = 0 To myPanel.Controls.Count - 1
>>   c = myPanel.controls(I) ' one of the child controls is a dataGridView
>>   prs = c.getType().getProperties()
>>   for j = 0 to prs.count - 1
>>   ...
>> ' I am looking for the published properties only.
>>   if prs(j).canRead and prs(j).canWrite then
>>  ' for the datagridview, I am getting the propety
>>   propName = prs(j).name
>>   propValue = prs(j).getValue(c, nothing) ' *** here I get sometimes an
>> exception : TargetParameterCountException was unhandled.
>> parameterCountMismatch
>>
>> ....
>>
>> Why may be the reason for the exception (The control : DataGridView.
>> property : Item) ?
>
> TargetParameterCountException means that the count of the passed 
> parameters
> are incorrect. The 'Item' property requires two parameters as you can see
> via intellisense, in the object browser and in the documentation. The call
> would be:
>
>   value = prs(j).GetValue(c, New Object() {param1, param2})
>
> You'd have to pass the correct parameter types. You get the parameter 
> information
> by calling
>
>   dim pi as parameterinfo
>   pi = prs(j).GetIndexParameters(ParameterIndex)
>
> However, if you don't know what to pass to the GetValue method, it's not 
> possible
> to get the property value.
>
>> Also, "item" is not a published property, that may seen on design time.
>> I want to see only properties, which are seen on design time.
>
> Item is a Public property. You may want to check the custom attributes of
> each property. Call prs(j).GetCustomAttributes. Then you can check the 
> type
> of each attribute, for example.
>
>   dim prop = prs(j)
>   dim atts = prop.GetCustomAttributes
>
>   for each att in atts
>       if typeof att is 
> System.ComponentModel.DesignerSerializationVisibilityAttribute then
>            dim SpecialAtt = directcast(att, 
> System.ComponentModel.DesignerSerializationVisibilityAttribute)
>            debug.print (specialatt.visibility.tostring)
>       end if
>   next
>
> The DesignerSerializationVisibilityAttribute is one of the attributes 
> attached to the DataGridView's
> Item property. The other one is the 
> System.ComponentModel.BrowsableAttribute.
>
> Anyway, even those properties that don't have any of these attributes 
> attached, may have multiple
> parameters. If you don't know what to pass, you can only retrieve the 
> values of those that's
> GetIndexParameters method returns an empty array, i.e. with 0 items.
>
>
> -- 
> Armin 

0
Mr
6/19/2010 8:12:42 PM
Reply:

Similar Artilces:

Getting to the right ID on a continuous form
On a continuous subform, I have a button that opens up a simple form that allows the user to enter a note for a particular record. a field1 field2 [btn] b field1 field2 [btn] c field1 field2 [btn] . . . The problem is that if the user clicks, say, the button on the third record down (c), that opens the note for the first record in the continuous form (a). No matter which record's button the user clicks on the continuous form, it always opens to the first record's note. What I need to do, I guess, is get the ID of the record that the user is c...

Ole object list
Hi, Is there any way to add a kind of object (ex.: Journal document or OneNote document) in the list of objects of the windows who open after we right clic the command "Insert an object" in a Ole field in Access 2007 (Vista system)? Thanks! ...

Email Attachments getting converted to Windows format in Outlook
When I open my IMAP mailbox using outlook it deletes and re-inserts any emails that have image attachments. The new email on the server is converted to a winmail.dat attachment format. This causes problems when I try to read the same file using my PDA since it can not read the winmail.dat format. How do I make outlook stop "auto" converting my attachments to winmail.dat. I have outlook configured to send email with plain text to prevent this problem when I send email I was shocked to learn that outlook was converting my email when I access the mailbox. Any help would be appreci...

Money 2004 or keep Quicken 2003 (later get 2004)????
Standard question to ask advice about: - Now a Quicken user and should stay a Quicken user? - Change to Money 2004?? -- Why change?? -- Why not change?? I do home finances, connect to bank (two) to pay bills and to track checking accounts and credit card purchases and payments. Not investing in stocks, etc. Do taxes using Turbo Tax but don't import information to do that. Used Money a few years ago -- it did not allow single check printing on my printer at the time, while Quicken did, so I stayed a Quicken user. Thank you. You folks have been a big help...

how do i get rid of small "th"
I'm just wanting to insert a regular sized "th" after writing the date but Word automatically makes it smaller - please help me. Thanks In the AutoFormat As You Type dialog, clear the check box for "Ordinals (1st) with superscript." The path to this dialog is: Word 2003 and earlier: Tools | AutoCorrect (Options) | AutoFormat As You Type Word 2007: Office Button | Word Options | Proofing | AutoCorrect Options | AutoFormat As You Type In existing text, remove the superscript property by selecting the text and pressing Ctrl+Spacebar. -- Suzanne S....

copy formula+value
I have this 2 columns. I want to copy this two and paste them to a new row with exact the same formula, value and cellreference. =3D'Z:\F=F6retag\[filename1.xls]Best=E5nd'!$A$4 =3D'Z:\F=F6retag\[filename1.xls]Best=E5nd'!B18 The result: =3D'Z:\F=F6retag\[filename1.xls]Best=E5nd'!$A$4 =3D'Z:\F=F6retag\[filename1.xls]Best=E5nd'!B29 I want the B29 to be B18. I do understand that I could change B18 to $B$18 above but I don't want to do that. In some cases when I copy I want the B18 to be B19,B20,B21,... and this works fine. But how could I make a copy without ...

I get message "Unable to open Pub doc".
I have had a couple people send me a Publisher document as an email attachment, but when I try to open it, I get a message: "Publisher cannot open the file". I thought it was because the doc was created in a newer version than what I had. Now I'm not sure because I tried to open another pub doc I received from a different friend while at school. The computer has 2002 version and I still can not open docs. Can you tell me why, and what I can do? Could be your virus software. How to use Office programs with the Norton AntiVirus Office plug-in http://support.microsoft.com/k...

Multi Value Combo Boxes
Hello: One of the new features of Access 2007 (sometimes criticized) is the ability to create a table field as "Allow Multiple Values" using the Lookup Wizard when specifying the data type. This shows the values with a checkbox and allows the user to select multiple items (i.e. select CA, OR, WA as states in which a business resides). I was hoping to just define a table field as Text and then create the "Allow Multiple Values" when creating a combo-box on the form. The form wizard does not seem to create the same objects as when doing it in table design ...

why isnt password reset available fromm the properties menu
I'm new to exchange (we just migrated from GroupWise) and the only way I can reset a password is to right click on the user in mmc. If I double click the user, I get every option except 'reset password" Is this just the way it is? Or am I missing something. thanks in advance mike In the last exciting episode, swamptrash67 <swamptrash67@verizon.net> wrote: >I'm new to exchange (we just migrated from GroupWise) and the only way I >can reset a password is to right click on the user in mmc. If I double >click the user, I get every option except 'reset...

How to get automatic completion of email recipients
Brand new Outlook 2003, WinXP user I imported my mail messages and contacts from OE6. If I create a new mail message. In OE, I begin typing the recipient=92s name. Let=92s say I type Bill S. At this moment OE automatically brings up the name Bill Smith. In my new Outlook, this automatic search and fill-in isn=92t working. How do I turn it on? Tools>Options>autocomplete The entries are added over time / usage "PT" <inconnu3939@gmail.com> wrote in message news:391d5c84-4b77-4238-9961-b93f1ae66a15@u41g2000yqe.googlegroups.com... Brand new Outlook 2003,...

Ownerdraw CListBox
I'm annoyed that I can't figure this out myself, but here goes. I had a standard listbox working in a dialog. Then I decided to make it ownerdraw. I derived a class from CListBox, but I really don't know how to "attach" an object of my listbox class to the dialog in place of the original listbox (which I just dragged in in the dialog editor). I was using DDX_Control() to access the original listbox, but changing the type of my DDX variable to my derived class didn't do the trick (I really didn't expect it to). Should I even be using DDX_Control() with a deriv...

The ol' "An object could not be found." message when trying to close a PST
As noted in the subject, I'm getting this message when trying to close my "Archived Folders" PST file. My searches using the KB as well as Google turned up a few instances of this message, but none had to do with closing a PST file. I've tried: - Renaming the "Archived Folders" PST, then re-opening OL2002. - Moving the "Archived Folders" PST to another directory, then re-opening OL2002. - Creating a new PST, copying everything from the archive PST into the new one, compacting the new one, and substituting it for the original "Archived Fol...

Access query to get monthly and quarterly report
Hi, I will require 5 tabs in the report. All reports should be able to use the same result set, but not all columns will appear in each report. They will just present the data differently. for example: if month falls with in the start and end date should show yes otherwise No. Immediate help will be appreciated.. thank you in advance Startdate Enddate Nov-09 Jan-10 Jun-12 Dec-12 12/11/09 6/30/2012 Yes Yes Yes No Startdate Enddate Q3-09 Q4-09 Q2-12 Q4-12 12/11/09 6/30/2012 No Yes Yes No Submitted via EggHeadCafe - Software Developer Portal of C...

Getting VISTA Control panel\Programs look and feel....
Hi All, In one of my application development, I need to present the information similar to how VISTA shows in Programs (which is under Control Panel). I could not get what has been done to get this look? If you go to "Control Panel" and then if you go to "Programs" in that, it has "Programs and Features" option. Just below the "Programs and Features" it has various options "Uninstall a program", "Turn windows features on or off" etc. It appears to me that it is a list control. But in the rows there is a line (seperator kind ...

Need Help With Macro to set a value in new sheets
Hey everybody. I am using a variant of Dave Petersen's macro code to create a new sheet and rename that sheet based on a list of values in Sheet_2. Here is what I have so far: Sub CreateNameSheets() ' by Dave Peterson ' List sheetnames required in col C in a sheet: Sheet_2 ' Sub will copy sheets based on the sheet named as: Sheet1 ' and name the sheets accordingly Dim TemplateWks As Worksheet Dim ListWks As Worksheet Dim ListRng As Range Dim myCell As Range Dim ListRng2 As Range Dim myCell2 As Range Set TemplateWks = Worksheets("Sheet1"...

Iterating the combo box and displaying the value after each change on seprate sheet.
Here i have a combo box form control, from where i will be picking the value and displaying it on other sheet. Now i am updating the sheet with combo box control, value is getting pasted on Consolidated-Report using: Worksheets("Consolidated-Report").Range("a9").Value = Me.ComboBox2.Value If now i again go back to combobox sheet and change the value, same cell is getting updated. I need to move to next row for each time the value is updated in combo box and paste the same on Consolidated-Report sheet. Note: A Combobox from the Control Toolbox has the name ComboBoxN; ...

How to add new node with value?
I want to create new node, and then save it to file. I can add empty node with attributes, but I don't know how set new value for the node: String *strMake = this->txtMake->Text; String *strModel = this->txtModel->Text; XmlDocument* XmlDoc = new XmlDocument(); try { // Get the XML file and load it in the XmlDocument variable XmlDoc->Load(S"c:\\cars.xml"); // Create the new element XmlElement *Elm = XmlDoc->CreateElement(S"car"); // Create its attributes Elm->SetAttribute(S"Make", strMake); El...

Show a sheet1 row in sheet2 based on values in col sheet1.A
Hello! Please help! I have a large sheet with numerous rows in sheet1. Column A in sheet-1 is either blank or has a value. I want to show in sheet-2 (a new sheet) all sheet1 rows that have a value in column A. Thanks in advance, Michelle Hi Michelle one way: - select your range in sheet 1 - goto 'Data Filter - Autofilter' - Filter all relevant row - copy the row and paste them on sheet 2 -- Regards Frank Kabel Frankfurt, Germany Michelle wrote: > Hello! > Please help! > I have a large sheet with numerous rows in sheet1. Column A in > sheet-1 is either blank or ...

Cannot access office out, getting POP3 Reporting Error 0X80042108
Hi there, i understand MS made some changes and now i am locked out from my MS Office Outlook. I get a POP3 Reporting Error # 0X80042108. The server does not recognize me. Is there any instructions on how to set or re-set this? Is there any REAL PERSON i can talk to for FREE Tech Support??? Thanks, Ray @ manauto@msn.com The changes were to how Outlook pulls Hotmail. Verify your settings against this: http://support.microsoft.com/kb/813514/en-us "Ray" <Ray@discussions.microsoft.com> wrote in message news:23A6252E-7B5F-454D-BB5A-5C9AB2B24DCD@microsoft.com... > Hi there...

sum of values between two given dates
good morning here is my problem In column A I have some dates, and in column B corresponding quantities (km ran by a marathon man) what I need is to compue the sum of km in a given month. In other words, the SUM(BXX:BYY) function should have, within it a pointer. for example, say for september 2008, it should find the first date of september 2008 (say cell A15), and give to teh sum function the value 15 instead of the XX above. Then look for the latest available date in september, say A21, and give the sum function the value 21 instead of YY. I know/suspect that it has to be done through addre...

OnAccept getting socket handle
Hi, how is it possible to get the CAsyncSocket-Handle in the OnAccept- method? I don`t want to install one thread for each connection - I`ve one thread for all http-connections. void ConnSoc::OnAccept(int nErrorCode) { //doing some error stuff // New connection is being established CAsyncSocket soc; //using threads / detach / attach if(!Accept(soc)) //error-handling CAsyncSocket::OnAccept(nErrorCode); } If you install a thread for each connection, a new socket is installed with detach / attach handling. But what`s a suitable solution using only one thread...

Get month from date
Useing VBA, how to I get the month from a date in range("a1") as text. Eg if date = 30/1/02, Month = "January" or 30/10/05 then month = "October". I want to worksheets with the month. Regards Robert MonthA = format(range("a1"),"mmmm") -- Kind regards, Niek Otten <RobcPettit@yahoo.co.uk> wrote in message news:1131520581.324157.176670@z14g2000cwz.googlegroups.com... > Useing VBA, how to I get the month from a date in range("a1") as text. > Eg if date = 30/1/02, Month = "January" or 30/10/05 then month = >...

how to bypass the security prompts when get the internet header of the mail #2
I get the internet header of the mail using CDO 1.2, Will this trigger the security prompts in secure versions of Outlook 2000 and how to bypass it. Thanks a lot! ...

Email Getting stuck in the outbox
I have ONE end user getting emails stuck in his outbox, usually between the times of 4pm and 5pm only. He is running all the latest updates on the OS (XP) and on Office 2007. We are running Exchange 2007 with all the patches available to date as well. At first I looked at our exchange server to see if that is where the problem resided. I did some tweaking there, but nothing ever remotely cured this problem. So, I started to concentrate on his laptop. One of the first things I did was update all his contacts by creating a second contacts folder in outlook and copying all his...

Subquery returned more than 1 Value in Manufacturing
Working in the Edit MO Status window. Can search by MO number, but if try to search by any ranges (ex: date, site, etc), get error: [Microsoft][ODBC SQL Server Driver][SQL Server]Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <+, >, >+, or when the subquery is used as an expression. We are running GP v. 9.0. Any ideas? ...