DataGridView Sorting Sorted!

I encountered this issue whilst developing my plugin Mission Control; if the dotNet dataGridView has been sorted using the column headers, it seems that the indexes returned by (dgv.selectedRows()).item[#].rowindex or the tags returned by (dgv.selectedRows()).item[#].tag.value all point to the non-sorted rows of the dgv.

This would be a big problem for my plugin as being able to sort the spreadsheet is a key functionality of the tool and the only alternative method I could think of was to put all my data through a dataTable… not something I was keen to implement at this stage of the development.

Thankfully, after a little experimentation I realised that dgv.selectedRows() wasn’t the only way to obtain the current selection of a sorted dgv; I could have used dgv.selectedCells() and then collected the unique rowindex’s or row pointers from my tags. Although this is slightly heavier in terms of processing more data (especially with large selections of many columns), a solution that works slowly is better than no solution at all!

Problem solved!

…thanks due to DenisT (cgtalk forums) for the encouragement!

Skip to toolbar