How can I Invoke a particular event programatically? Lets say a double click event on datagrid?
Printable View
How can I Invoke a particular event programatically? Lets say a double click event on datagrid?
good ol win32 api. its a little more involved than you might think.
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).
I 100% agree with that.Quote:
Originally Posted by jhammer
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.
Thanks a lot for your replies.
Could you give a code example as to how to do it? Thanks.
Please tell us exactly what you want to do.
Here is what I was trying to do:
I was trying to autosize datagrid columns using the following:
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.Code:
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});
}
Hope that would explain it, if I need to describe something more please let me know. Thanks in advance.