DataGridView load event

Posted on 2011-10-14
Last Modified: 2012-06-27

I am using Windows forms. I have a DataGridView on my form. I need to hook up the event which occurs on initialization of DataGridView. I know that I can catch event from my form (on which DataGridView is placed), but I can't to this, because I have several DataGridViews on my form and I need to operate on columns of each of them.

I thought of catching the parents Load event of DataGridView, which is System.Windows.Forms.Control class, but I don't know how to do this? Any idea?

Greetings, Frenky
Question by:AntonioRodrigo
    LVL 33

    Expert Comment


    Author Comment

    Thanks for answer - but Paint event is triggered multiple times (f.e. if you minimize control and then maximize it back again). I need an event which is triggered only once - at control initializing.
    LVL 33

    Expert Comment

    I don't any other then using the Form.Load event...
    LVL 83

    Accepted Solution

    You mean you want to execute same code against each datagridview?

    You can use a single event handler with all the grids. For example


    AddHandler dgv1.DataSourceChanged, Addressof MyHandler
    AddHandler dgv2.DataSourceChanged, Addressof MyHandler

    Then in the event, you can use sender object to determine which grid raised the event.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now