I have looked and found one question which was similar, though did not resolve my issue - that other question was datagridview-is-blank-after-changing-datasource-at-runtime
I am sure this is a simple question with an even more simple answer..Working on my first Windows Forms application and finding some things a lot different from ASP.Net :)
So in this application I have the following:
- Main Form
- Toolbar on this form, opens up a second form to set application settings
- This second form has a tab control (2 tabs) with various textboxes/checkboxes/combolists/buttons
- All of these work perfectly.
- On the second tab of this second form, along with more textboxes etc, I have added a DataGridView; called printerListGrid
In the code-view of this form I am trying to bind a List(Of Printer) to it
printerListGrid.DataSource = AppContext.printers.printerList
When I run my app and go to the form/tab the DataGridView is blank.
I have also tried:
printerListGrid.Columns.Clear()
printerListGrid.AutoGenerateColumns = True
printerListGrid.DataSource = AppContext.printers.printerList
Again - it's blank.
While debugging I can see that my printerList contains 2 printer objects. I can also see that these have been set to the printerListGrid by viewing the contents of the .DataSource property. Yet, the DataGridView is still blank.
I'm guessing there must be some way to re-render the grid?
For the sake of code-discolsure; this is what is in the List(Of Printer)
Public Structure Printer
Public id As Integer
Public name As String
Public material As Enums.Materials
Public outputFolder As String
End Structure
Let me know if there is any more code/description you need to provide help.
UPDATE:
I forgot to mention. I am trying to set the DataSource in a Private Sub which is called on the forms Load event MyBase.Load
UPDATE #2
I continue to play with this, trying to get it to work - I might be totally misunderstanding the control and its purpose.. anyway, I have also tried the following:
printerListGrid.AutoGenerateColumns = False
Dim col As DataGridViewColumn = New DataGridViewTextBoxColumn()
col.DataPropertyName = "name"
col.HeaderText = "Name"
printerListGrid.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
col.DataPropertyName = "material"
col.HeaderText = "Material"
printerListGrid.Columns.Add(col)
col = New DataGridViewTextBoxColumn()
col.DataPropertyName = "outputFolder"
col.HeaderText = "Output Folder"
printerListGrid.Columns.Add(col)
printerListGrid.DataSource = AppContext.printers.printerList
This results in at least the grid showing rows; appears like 2. Yet they are not populated with the data from List(Of Printer)...