Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
===================================================
(Improved question)

This is improved question, please first see the 'original question', and then the following text in 'Answer1', thanks OriginalGriff provide the suggestion to try the following lines :

C#
foreach (Control c in propertyGrid1.Controls)
{   c.MouseClick += new MouseEventHandler
                   (MyMouseClickEventHandlerWhatEverItIsCalledInYourCode)
};


But when I do verification, it shows can not generate "propertyGrid1.Controls" ! However, I see there are events of ControlAdded and ControlRemoved can be selected, why it can not have "propertyGrid1.Controls" !? Can any one helps to show the root cause ?


====================================================
(Original question)

I write a Window form application, and place a PropertyGrid on form, and in PropertyGrid atrribute table :

1. I assign object to the SelectedObject attribute.
1. Enable the 'MouseClick' event on.
2. Write one line 'int i=0' in the 'MouseClick' event (for debug only).
3. Run it, and it works fine.

However, when I click the PropertyGrid, the 'MouseClick' event will not be invoked !
But, when I change the event setting to be 'SelectedGridItemChanged', and click differnt
grititem on PropertyGid, it then can invoke the 'SelectedGridItemChanged' event !

Question :
1. How can I let the 'MouseClick' event be invoked ?
My purpose is to detect if any griditem is clicked, and then check if the griditem is
the one I would like to do advanced process.
2. Actually, I would like for user to edit some griditems, which has string array of text.
I've searched some articles in CodePage, which have mentioned about the way to reach
it, but all seems be so complicated, I surpose there should have simple way to reach
my request, can any one show the simple and detailed sample to me for reference ?

note :
1. The 'SelectedGridItemChanged' event can not meet my request, since I would not do the
dedicated advanced process when item is just changed, and, I would do it when user
right click mouse (to edit the text of the clicked griditem)
2. The system has built-in function of text viewing for griditem, such as when moving
mouse on the value row of griditem which has type of string array, the system will
automatically show the whole text window for user to view. But, I surpose it's not
enough for user to do editing, so I request to let user to click the griditem, and
then can show a muliple line textbox for user to edit.
Posted
Updated 26-Jan-11 0:04am
v2
Comments
OriginalGriff 24-Jan-11 4:03am    
Answer updated

1 solution

The PropertyGrid contains child controls which completely fill the controls working area: As a result, the overall control MouseClick event is never fired.
The Click event is, sometimes (but not always, it depends on what part of the control you click on).

If you really need the MouseClick event, then you will have to follow through the PropertyGrid instance Controls list recursively and hook into the MouseClick events there.

"=======================================
Thanks of your response.
Regarding 'to follow through the PropertyGrid instance Controls list recursively and hook into the MouseClick events there.', could you write some lines (or describe more words), so that I can image what it look like ?
==========================================="


In your form:
C#
foreach (Control c in propertyGrid1.Controls)
   {
   c.MouseClick += new MouseEventHandler(MyMouseClickEventHandlerWhatEverItIsCalledInYourCode);
   }
You may need to recurse through sub control lists, but that is a simple matter to implement.
 
Share this answer
 
v2
Comments
Sports Kuo 24-Jan-11 3:46am    
=======================================
Thanks of your response.
Regarding 'to follow through the PropertyGrid instance Controls list recursively and hook into the MouseClick events there.', could you write some lines (or describe more words), so that I can image what it look like ?
===========================================
Sports Kuo 24-Jan-11 20:41pm    
===========================================
Thanks.
But it can not generate "propertyGrid1.Controls" ! could you double confirmation its function ?
I see there are events of ControlAdded and ControlRemoved, why it can not have "propertyGrid1.Controls" !?
===========================================
Sports Kuo 30-Jan-11 21:04pm    
==========================================
Thanks SA fully supports !
==========================================

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