Solved
VB.Net DataGridView - RowsAdded Fired Twice
Posted on 2013-11-25
Hopefully I am just missing something obvious here, but for the life of me I cannot find anything.
I have a form on which there is a DataGridView that is bound directly to rows in a DataSet. All of this has been set up using the designer. I do not touch the binding related properties anywhere in my code.
The DataGridView consists of bound fields and unbound fields, the latter of which I calculate and populate in the RowsAdded() event (e.g. there is an invisible data bound field that is a number of seconds, and an unbound visible field that is that value formatted into HH:MM:SS).
Anyhow, the issue I have is that the RowsAdded() event seems to be firing 4 times, the first time with e.RowIndex = 0 and e.RowCount = 1, the second with e.RowIndex = 1 and e.RowCount = 88 (which I was expecting), but it then fires a third and fourth time with exactly the same sequence of parameters.
I do a fair bit (not excessive) of formatting in the event (cell background colouring, value formatting etc), and the fact that it is all being executed twice is obviously going to unnecessarily slow my application down.
I have looked everywhere and cannot fathom out why it would be being fired twice - the binding is done in design and never changes, and the Fill() is only called the once.
Any clues as to what I might have done wrong ?
Thanks,
Matt