[Webinar] Learn how to a build a cloud-first strategyRegister Now


One button/event to handle multiple datagrids on form

Posted on 2006-06-01
Medium Priority
Last Modified: 2010-04-23
I have a application where I have several different datagrids on one form.  I would like to use ONE set of buttons/events to handle ALL datagrids depending on which grid is the "active grid", instead of duplicating buttons for each one.  Is there a way to pass  an "active grid" object, or something similar so that the same single button event is used for all datagrids on the form?
Question by:mgb1000
LVL 17

Accepted Solution

ZeonFlash earned 500 total points
ID: 16810704
As soon as you press a button, the active grid will lose focus, so the "active" grid will be come inactive.  You could have a private variable that keeps track of which grid is the active one, and is updated upon every grid's .GotFocus or .LostFocus event.

    Private dgActive As DataGrid

    Private Sub DataGrid_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.GotFocus, DataGrid2.GotFocus
        dgActive = CType(sender, DataGrid)
    End Sub

    Private Sub DataGrid_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.LostFocus, DataGrid2.LostFocus
        dgActive = Nothing
    End Sub

Then in your button events, you would just have to use reference dgActive as the datagrid to perform the operations on.

Author Comment

ID: 16811441
Thank you!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

865 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