title: Bind list of object to datagridview in VB
body: <p>I want to bind a list of objects to a DataGridView in VB. </p>
  
  <p>It worked first with using datagrid.Rows.Add(...) for each result, but that blocks the program.
  I've read it could be solved by binding a list of objects to the DataGridView with .DataSource.
  But it don't work, my datagridview remains empty...</p>
  
  <p>What is wrong? Is it something in the GUI-code (see below)?</p>
  
  <p>This where the logic happens:</p>
  
  <pre><code>Public queryList As New List(Of _study)
  
  ...
  
  If _objResponse.Status = CurrentStatus.Pending Then
          Dim _newStudy As New _study
  
          ' Parse one study from the response (_objResponse.Dataset.[Get](Of String)(DicomTag.StudyDate))
          _newStudy._studyID = _objResponse.Dataset.[Get](Of String)(DicomTag.StudyInstanceUID)
          _newStudy._name =  _objResponse.Dataset.[Get](Of String)(DicomTag.AccessionNumber)
  
          ' Save study info for later use
          queryList.Add(_newStudy)            
  
  ElseIf _objResponse.Status = DicomStatus.Success
          dgvResults.DataSource = queryList
          ...
  Else
          MsgBox("Failed")
  End If
  </code></pre>
  
  <p>Here is the _newStudy class:</p>
  
  <pre><code>Public Class _study
  
     Private _studyID As String
     Private _name As String
  
     Public Property _studyID() As String
       Get
          Return _studyID
        End Get
        Set(ByVal value As String)
          _studyID = value
        End Set
     End Property
  
     Public Property _name() As String
       Get
          Return _name
       End Get
       Set(ByVal value As String)
          _name = value
       End Set
     End Property
  End Class
  </code></pre>
  
  <p>And here is the code of the DataGridView() GUI:</p>
  
  <pre><code>Private colName As System.Windows.Forms.DataGridViewTextBoxColumn
  Private colID As System.Windows.Forms.DataGridViewTextBoxColumn
  Private dgvResults As System.Windows.Forms.DataGridView
  
  ...
  
  Me.dgvResults = New System.Windows.Forms.DataGridView()
  Me.colID = New System.Windows.Forms.DataGridViewTextBoxColumn()
  Me.colName = New System.Windows.Forms.DataGridViewTextBoxColumn()
  
  Me.dgvResults.AllowUserToAddRows = false
  Me.dgvResults.AllowUserToDeleteRows = false
  Me.dgvResults.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill
  Me.dgvResults.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
  Me.dgvResults.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.colID, Me.colName})
  Me.dgvResults.Location = New System.Drawing.Point(6, 19)
  Me.dgvResults.Name = "dgvResults"
  Me.dgvResults.ReadOnly = true
  Me.dgvResults.Size = New System.Drawing.Size(540, 206)
  Me.dgvResults.TabIndex = 2
  
  'colID
  Me.colID.HeaderText = "Study ID"
  Me.colID.DataPropertyName = "_studyID"
  Me.colID.Name = "colID"
  Me.colID.ReadOnly = true
  
  'colPatientName
  Me.colName.HeaderText = "Name"
  Me.colName.DataPropertyName = "_name"
  Me.colName.Name = "_name"
  Me.colName.ReadOnly = true
  
  ...
  
  CType(Me.dgvResults,System.ComponentModel.ISupportInitialize).EndInit
  </code></pre>
  
  <p>I think the  DataPropertyName is correct to get the link between the objects and the datagrid, right...?</p>
  
  <p>Thanks a lot!</p>