Working with a DataGridView programmatically - creating and binding to a datasource in code - not working??

Hi I am trying to create a DataGridView in code, not for display purposes but as a temporary holder for exporting to excel - but when I go to export from the DataGridView it does not contain any data. Any ideas? I have checked and the business object has data but it is just not being assigned to the DataGridView.

Your help would be appreciated.

Dim dgv As New DataGridView
dgv.AutoGenerateColumns = True
dgv.DataSource = MyBusinessObject
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you can provide code that would be helpful..

Based on the 3 lines of code, it seems you are not binding the data to the gridview :-)

You can add the dgv control to the forms controls collection and then hide it, with this you can use the Datagridview as you want

'*************YOUR CODE
Dim dgv As New DataGridView
dgv.AutoGenerateColumns = True
dgv.DataSource = MyBusinessObject

'*************ADD THIS CODE
dgv.Visible = False


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jazz__manAuthor Commented:
Thanks, thats probably the best way forward.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.