I have a Windows.Forms form with two DataGridViews: dgvStockData and dgvStockData_Daily. Both DGVs are unbound, have AllowUserToAddRows = false and ReadOnly = true and both always contain considerably more rows that are displayed so scroll bars are enabled. When the user selects a stock row from dgvStockData, daily data on the particular stock item is loaded into dgvStockData_Daily by first clearing dgvStockData_Daily.Rows.Clear() then filling using dgvStockData_Daily.Rows.Add(daily_row). When dgvStockData is filled (on the Load event of the main form), the first stock item is automatically selected, firing an event which loads the corresponding daily data and draws dgvStockData_Daily. The problem is when the user scrolls to the end of dgvStockData_Daily.
The first time the user scrolls to the end of dgvStockData_Daily, everything looks as expected - the last row added is displayed at the bottom of the DGV and there is space below the last row where the input row would be, if it was enabled. If another item is selected from dgvStockData, dgvStockData_Daily clears and refills as expected. However, when the user scrolls to the end of dgvStockData_Daily, the row that should be blank (should be the control background color) is filled with data from a random row. This phantom last row cannot be selected and doesn't go away with a Refresh(). Scrolling up then back down does not correct the problem unless the user scrolls to the first row, then back down. The next refill of dgvStockData_Daily usually causes the problem again.
If I programmatically set AllowUserToAddRows = true when the phantom row is actually displayed, the input row appears but the phantom row reappears when AllowUserToAddRows is set false again. The issue is not because dgvStockData_Daily is unbound. Using a BindingList that is filled and cleared on the UI thread (either directly on the UI thread or via marshalling from another thread) does exactly the same thing.
Is there a way to force correct redrawing of the input line region when AllowUserToAddRows is false? Is there something I've omitted or done incorrectly or is this a bug in the DataGridView?
The problem occurs when using VS 2010 Ultimate and .NET 4 on Windows 7 (both x32 and x64 versions).
Any help would be gratefully received. Wishing you all a wonderful and peaceful holiday season.