Coordinating Multiple selected rows in multiple DataGridView

Posted on 2011-10-25
Last Modified: 2013-12-16
I have 3 DataGridView's which each reference a BindingSource that references a DataTable in a DataSet.  Each of the DataGridViews's displays a different set of the columns in the DataTable.  The BindingSource correctly coordinates the data shown in each DataGridView nicely, as expected.  The BindingSource also coordinates the CurrentRow to be the same in each DataGridView.  Very nice, as expected. However, as we know, the CurrentRow is not necessarily a selected row.  Furthermore, while we can have only one current row, we can have multiple selected rows.  I would like to set up my application so that each DataGridView will always show the same set of selected rows.  I know about the DataGridExposed members for SelectedRows, Selection Changed events.  I know I can make a row selected with the DataGridViewRow.Selected = true.  I have tried some programatic control of the Selected Rows, but because of the common BindingSource I get a lot of recursive events and the entire process soon gets quite messy and I just can't seem to get it to work right.  Any suggestions on how to approach this would be appreciated.
Question by:thomehm
    1 Comment
    LVL 32

    Accepted Solution

    i solved a similar problem by ignoring recursive events caused by active selections. you would need a kind of stopflag for each grid which causes the eventhandler of selection changes to immediately return. the initial state of all stopflags is false. when the selection change handler of one of the grids gets an event it sets the stopflags of both other grids to true. then, actively select/unselect the row for the other grids by initial event.

    the main problem with this approach is to reset the stopflags. that depends whether the events for the other grids were caused immediately by active row selection or were performed delayed. in the first case you simply can reset the stopflags after active selection (cause the events already were ignored) in the second case you could send a user message via PostMessage and then reset all stopflags in the handler of that message.


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now