CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2005
    Posts
    71

    How To: Invoke an event.

    How can I Invoke a particular event programatically? Lets say a double click event on datagrid?

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: How To: Invoke an event.

    good ol win32 api. its a little more involved than you might think.

  3. #3
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: How To: Invoke an event.

    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).

  4. #4
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: How To: Invoke an event.

    Quote Originally Posted by jhammer
    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.

  5. #5
    Join Date
    Sep 2005
    Posts
    71

    Re: How To: Invoke an event.

    Thanks a lot for your replies.

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

  6. #6
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

  7. #7
    Join Date
    Sep 2005
    Posts
    71

    Re: How To: Invoke an event.

    Here is what I was trying to do:

    I was trying to autosize datagrid columns using the following:
    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});
    }
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured