Click to See Complete Forum and Search --> : How To: Invoke an event.


Taurian110
October 17th, 2005, 01:15 PM
How can I Invoke a particular event programatically? Lets say a double click event on datagrid?

MadHatter
October 17th, 2005, 01:17 PM
good ol win32 api. its a little more involved than you might think.

jhammer
October 17th, 2005, 03:12 PM
Invoking such events looks like really bad design. In most cases this can be avoided by calling a function.

If you really need to, you could derive from DataGrid, and invoke the DoubleClick event, but you will need to create a MouseEventArgs with some coordinates (The real ones can be extracted from Cursor class).

MadHatter
October 17th, 2005, 03:30 PM
Invoking such events looks like really bad design.
I 100% agree with that.

you can add the event handler for that action, then call the event handler. its not invoking that event, you using what happens when that event is triggered w/ out clicking away.

Taurian110
October 18th, 2005, 11:59 AM
Thanks a lot for your replies.

Could you give a code example as to how to do it? Thanks.

jhammer
October 18th, 2005, 12:37 PM
Please tell us exactly what you want to do.

Taurian110
October 18th, 2005, 03:29 PM
Here is what I was trying to do:

I was trying to autosize datagrid columns using the following:


Type t = dgTC.DataSource.GetType();
MethodInfo m = t.GetMethod("ColAutoResize", BindingFlags.Instance | BindingFlags.NonPublic);
for (int i = dgTC.FirstVisibleColumn; (i< dgTC.VisibleColumnCount); i++)
{
m.Invoke(dgTC, new object[]{i});
}

As far as my understanding goes, ColAutoResize is called whenever user double clicks on the splitter b/w two columns. But eversince I added custom columns I was getting excpetion. But when I would double click on the splitter it would still autosize it.... So, I was just trying to use the funcitonality that was used by datagrid when user would double click on the splitter.

Hope that would explain it, if I need to describe something more please let me know. Thanks in advance.