Tuesday, August 02, 2005

Winforms Datagrid Scrollbars

I don't get much chance to work with the DataGrid control in Winforms (.NET 1.1 Framework), but, damn does it seem buggy!

Like, today I had some code that was databinding against a DataTable within a DataSet. The first Databind() would result in scrollbars showing, but not being "live". That is, they did not appear to have their Min/Max and Values set per the data that was loaded in the grid (so, as a result, you couldn't use them to scroll the grid to see other rows or columns to the right, etc).

The second and subsequent Databind() operations would cause the scrollbars to work normally.

My solution (or workaround, depending on how you look at it) was to make sure that the DataGrid was enabled, and to SuspendLayout() prior to the Databind(). After the Databind() and any column resizing, I just did a ResumeLayout(), and voila! Working scrollbars every time.

Chalk this one up under the "I hope they fixed it in 2.0" category.