Click here to Skip to main content
16,009,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write a window application form. There is one buuton on the form, when click it, the popram will create a new PropertyGrid, and set some features for it as below :

C#
PropertyGrid NewPropertyGrid = new PropertyGrid();
NewPropertyGrid.tag = CheckString;
NewPropertyGrid.PropertyValueChanged += new PropertyValueChangedEventHander(NewPropertyGrid_PropertyValueChanged);
NewPropertyGrid.SelectedObject = NewObject;


When user changes the value in the PropertyGrid's GridItem, the event below will be invoked.

void NewPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)


The question now is below :

How can I get the object of the PropertyGrid, so that I can get its tag (eg PropertyGrid.tag) and do further check in this event ?
Posted
Updated 5-Jan-11 23:12pm
v2

1 solution

C#
void NewPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)


Here "s" will give you the PropertyGrid as object. You need to cast it and use it

Update 1:
You can also check e.OriginalSource.


Update 2:
You are supposed to cast like,

((PropertytyGrid)s).Tag


or

(s as PropertyGrid).Tag



Mark it as answer if it helps you
 
Share this answer
 
v5
Comments
Sports Kuo 6-Jan-11 5:47am    
=======================================
Thanks, but when I use the folling line, it can't work :

(Property)s.tag

since there is no tag attribute for you to select, so I can't get (Property)s.tag.

Could write down the whole line for reference ? Thanks.
========================================
Sports Kuo 6-Jan-11 5:51am    
=======================================
Sorry, I correct my line below :
(PropertyGrid)s.tag.

Please show the workable line for reference.
Venkatesh Mookkan 6-Jan-11 5:56am    
Updated the answer.
Sports Kuo 6-Jan-11 10:16am    
========================>
I use VS2010, and I still can not find the e.originalsource, could you find it, and work well ?
============================>
Venkatesh Mookkan 6-Jan-11 11:01am    
void NewPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)

- "e" is the object of PropertyValueChangedEventArgs in the about statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900