• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Coordinating Multiple selected rows in multiple DataGridView

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now