I have a bound datagridview with about 1/2 a million records and may be sorted by any column. In the GUI user can select any number of rows (sometimes all of them with CTRL+A). From another source I get a large list of record IDs (up to 1000) and need to find out which of those IDs correspond to a selected row. I've tried many approaches, none of which perform fast enough. For instance:
Looping through the selected rows collection and looking for a match in the IDs list is out of the question because the SelectedRows count can be on the order of 1/2 million.
I also tried looping through the ID's list (which is typically on the order of 1000) and for each ID do a BindingSource.Find("Id", Value) which gives me the row index for each ID and I can then check if the Row is selected. This works fine if the grid is sorted by ID, but if it's not, the performance of Find() is too poor to be called 1000 times.
In short, i need a fast way to find the Row.Selected state for up to 1000 rows given the row object IDs. It seems the DataGridView or DataBinding should be able to handle this but it's not obvious how. Thanks in advance!