Windows Develop Bookmark and Share   
 index > Windows Forms General > PropertyGrid not catching mouse events
 

PropertyGrid not catching mouse events


Hello,

I'm looking for a way to catch mouse clicks on a PropertyGrid and determine which property was clicked, in order to perform a task if the clicked property is of a certain type. The set value method which you need to implement for editing the property does not work either since it only triggers when changing the value.

The PropertyGrid does not seem to let me catch Click or MouseDown events.
Anyone done something like this successfully?

/Mats Uppstrom
Mats Upptrom  Wednesday, October 24, 2007 12:26 PM

Hi Mats Uppstrom,

The reason why PropertyGrid cannot receive Mouse event is that PropertyGrid contains some child controls which prevent the PropertyGrid receive Mouse event. You can loop through all child controls and register Mouse event for these controls. Check the following code:

Code Block

PropertyGridP

public partial class Form5 : Form

{

public Form5()

{

InitializeComponent();

}

private void Form5_Load(object sender, EventArgs e)

{

foreach (Control c in this.propertyGrid1.Controls)

{

c.MouseClick += new MouseEventHandler(c_MouseClick);

}

}

void c_MouseClick(object sender, MouseEventArgs e)

{

Control c = (Control)sender;

MessageBox.Show(c.GetType().FullName);

}

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, October 26, 2007 10:38 AM
Hi Rong-Chun Zhang,

thank you for the clarification and nice example, unfortunately it does not work as desired. Running the example, I can get the names of the constituent components of the PropertyGrid. However the region I'm interested in (the property value fields themselves) seems to be the only region which still does not respond to clicks. I'm guessing I would have to go further into that component (PropertyGridView?) to catch those clicks, but that class is internal.

Maybe I should describe the problem a little better:
I have some property values that are file names, editable with the FileNameEditor class, that part works fine.
I would also like to make those files sort of hyperlinked, so that clicking on the filename itself would open the file for viewing (spawn external process).

I made a temporary solution, not pretty but it works reasonably ok for now - using the SelectedGridItemChanged event I can detect when another property is selected and then go from there.


/Mats
Mats Upptrom  Tuesday, October 30, 2007 3:34 PM

You can use google to search for other answers

Custom Search

More Threads

• File Selection
• Doubt regarding datagridview
• .NET Framework 2 AppDomainUnloadedException in Windows Forms Application
• AxWebBrowser in a user control, in a MDI application
• "Run time Error '49'" "Bad DLL calling convention"
• Problem with the Scrollbar corner painting
• regular control with a dialog frame
• costum controls with GDI+
• Dynamically loading user controls
• How to capture mouse click events outside my form using C#?