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
LVL 2
jazz__manAsked:
Who is Participating?
 
gamarrojgqCommented:
Hi,

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
Me.Controls.Add(dgv)
dgv.Visible = False

'***************CODE THAT USES THE DGV CONTROL
0
 
meetingexpectationsCommented:
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 :-)
0
 
jazz__manAuthor Commented:
Thanks, thats probably the best way forward.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.