Datagridview error : Value' should be between 'minimum' and 'maximum'

I was trying to populate data in DataGridView control. It was getting populated into it correctly. But when I was trying to scroll down it was throwing an exception like;

> Value of '352' is not valid for 'Value'. 'Value' should be between
> 'minimum' and 'maximum'. Parameter name: Value

    at System.Windows.Forms.ScrollBar.set_Value(Int32 value)
       at System.Windows.Forms.DataGridView.ScrollRows(Int32 rowCount, Int32 deltaY, ScrollEventType scrollEventType)
       at System.Windows.Forms.DataGridView.ScrollRowsByCount(Int32 rows, ScrollEventType scrollEventType)

The Dynamic binding was used to fill the Datagridview.

After a lot of debugging and searching this issue got resolved with just one statement.
I called dataGridView1.PerformLayout() after populating data.

Thanks to Google :)

5 comments:

  1. I had the very same proplem with a very same DatatGrid View. Thanks for the solution!

    Target platform: .Net 3.5 in VS2010 Express

    ReplyDelete
  2. Thank you for the soluction, I had 3 days finding why the gridview was not displaying all information.

    ReplyDelete
  3. Thanks a lot for the solution. I got the same error message and was searching very long for a solution. It is a great help.

    ReplyDelete

Labels

.net .Net Instrumentation logging .net localization Agile amazon amazon elasticache amazon services AppDomain Application Domain architecture asp ASP.Net authentication authentication mechanisms Byte order mark c# cache cdata certifications class classic mode cloud cloud computing cluster code-behind Combobox compilation Configuration providers configurations connection connectionString constructors control controls contructor CSV CTS .net types conversion database DataGridView DataSource DataTable DataType DBML delegates design pattern dispose double encoding Entity framework Events exception handling expiry fault contracts fault exceptions function pointers functions generics help HostingEnvironmentException IIS inner join instance management integrated mode javascript join left outer join LINQ LINQ join LINQ to SQL memory leak methods microsoft modes in IIS MSIL multiple catch blocks no primary key Nullable Osmos Osmotic Osmotic communication Osmotic communications page events page life cycle partial class PMI preserve precision points private contructor ProcessExit Project management properties property protect connectionString providerName providers query regular expression repository Responsive Web Design return type run-time RWD Saas self join session session expiry sessions singelton singleton pattern software as a service source control system SQLMetal string toolstrip ToolStrip controls ToolStripControlHost tortoise SVN ToString() try catch finally update wcf web application web design web site web.config where-clause xml