Sumrak
Sumrak

Reputation: 3748

DataGridView auto size columns without showing the grid

I need to get DataGridView column sizes without showing the the grid (for printing). I'm using data binding through DataSource (using BindingSource doesn't seem to work too).

For whatever reason I get wrong column sizes. If I show the grid in a form first, everything is fine. If I try to get column sizes after setting no DataSource and executing AutoResizeColumns(), columns are too wide (didn't autosize).

How can I force grid to do it's job without showing it?

Upvotes: 1

Views: 670

Answers (1)

Sumrak
Sumrak

Reputation: 3748

Fixed. Use CreateControl() to initialize control, binding, handle, etc.

Upvotes: 1

Related Questions