title: WPF VB.NET 4.0 DatagridComboBoxColumn binding at runtime
body: <p>I had a similar question for DatagridComboboxColumn but that shown me how to use the .itemsource to bind to an array outside of the datagrid. I am having a problem trying to bind to the collection that the datagrid is bound to at runtime.</p>
  
  <p>I have included a working test program for how I am approaching this.</p>
  
  <pre><code>Class MainWindow 
  
  Dim ServerInfoArray As List(Of ServerInfo) = New List(Of ServerInfo)
  
  Private Sub GetInfo(ByVal list As List(Of String))
      For Each server As String In list
  
          Dim tempip As ComboBoxItem = New ComboBoxItem
          Dim tempip2 As ComboBoxItem = New ComboBoxItem
          Dim sinfo As ServerInfo = New ServerInfo
  
          tempip.Content = "192.129.123.23"
          tempip2.Content = "23.213.223.21"
  
          sinfo.IPArray.Items.Add(tempip)
          sinfo.IPArray.Items.Add(tempip2)
          sinfo.ServerName = server
  
          ServerInfoArray.Add(sinfo)
          DataGrid1.Items.Refresh()
      Next
  End Sub
  
  Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
  
      Dim serverlist As List(Of String) = New List(Of String)
      serverlist.Add("Test")
      serverlist.Add("Random")
      serverlist.Add("Local")
      GetInfo(serverlist)
  End Sub
  
  Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
      Dim Col_Serial As DataGridTextColumn = New DataGridTextColumn()
      Col_Serial.Binding = New Binding("Servername")
      Col_Serial.Header = "Servername"
      Col_Serial.Width = 40
  
      Dim Col_IPArray = New DataGridComboBoxColumn()
      Col_IPArray.Header = "IP Addresses"
      Col_IPArray.IsReadOnly = True
      'Col_IPArray.ItemsSource = serverInfoArray ' Don't know how to do this.
      Col_IPArray.SelectedValuePath = "IPArray"
      Col_IPArray.DisplayMemberPath = "IPArray"
  
      DataGrid1.Columns.Add(Col_Serial)
      DataGrid1.Columns.Add(Col_IPArray)
      DataGrid1.ItemsSource = ServerInfoArray
  End Sub
  End Class
  
  Class ServerInfo
  
  Dim _Servername As String
  Dim _IPArray As ComboBox
  Public Property Servername() As String
      Get
          Return _Servername
      End Get
      Set(ByVal value As String)
          _Servername = value
      End Set
  End Property
  
  Public Property IPArray As ComboBox
      Get
          Return _IPArray
      End Get
      Set(ByVal value As ComboBox)
          _IPArray = value
      End Set
  End Property
  
  Public Sub New()
      _Servername = Nothing
      _IPArray = New ComboBox
  End Sub
  End Class
  </code></pre>
  
  <p>I can get all Strings and Boolean to bind.</p>
  
  <p>I do not know how I can bind this DataGridComboBoxColumn to the list of attached on the property. I cannot use XAML as I need to do this at runtime.</p>