title: ComboBox Column within databound DataGridView
body: <p>Im back again with another DataGidView question</p>
  
  <p>I am creating an application that allows the user to create a ticket for products purchased</p>
  
  <p>This form consists of a DataGidViewwhich allows the user to record the product details along with price and quantity information.</p>
  
  <p>Currently the DataGidView is data bound and data is saved using a data adaptor and command builder at runtime</p>
  
  <p>The columns are created automatically and then i set properties such as formatting options as follows</p>
  
  <pre><code>Private Sub SetTicketList()
  
      Try
          Con.ConnectionString = CropTrackMod.strConn
          SQLAdaptor.SelectCommand = New SqlClient.SqlCommand("SELECT ID, StockRef, Weight, EstimatedPrice, DespatchedQuantity,EstimatedTransportPer,VATRate, EstimatedTransportTotal,EstimatedVAT, EstimatedLineTotal,TicketRef FROM TicketDetail where ticketref ='x'", Con)
          builder = New SqlClient.SqlCommandBuilder(SQLAdaptor)
          Con.Open()
  
          Dim myTable As DataTable = New DataTable
          SQLAdaptor.Fill(myTable)
  
          dgvTicketDetail.DataSource = myTable
  
          'ID Column
          dgvTicketDetail.Columns(0).Visible = False
  
          'StockRef
          dgvTicketDetail.Columns(1).HeaderText = "StockRef"
          dgvTicketDetail.Columns(1).CellType.
  
          'Weight
          dgvTicketDetail.Columns(2).HeaderText = "Weight"
          dgvTicketDetail.Columns(2).DefaultCellStyle.Format = "0"
          dgvTicketDetail.Columns(2).DefaultCellStyle.NullValue = "0"
  
          'Price Per Unit
          dgvTicketDetail.Columns(3).HeaderText = "Price"
          dgvTicketDetail.Columns(3).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(3).DefaultCellStyle.NullValue = "0.00"
  
          'Quantity
          dgvTicketDetail.Columns(4).HeaderText = "Quantity"
          dgvTicketDetail.Columns(4).DefaultCellStyle.Format = "0"
          dgvTicketDetail.Columns(4).DefaultCellStyle.NullValue = "0"
  
          'Transport Cost Per Unit
          dgvTicketDetail.Columns(5).HeaderText = "TransportCostPer"
          dgvTicketDetail.Columns(5).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(5).DefaultCellStyle.NullValue = "0.00"
  
          'VAT Rate
          dgvTicketDetail.Columns(6).HeaderText = "VAT Rate"
          dgvTicketDetail.Columns(6).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(6).DefaultCellStyle.NullValue = "0.00"
          dgvTicketDetail.Columns(6).ReadOnly = True
  
          'Transport Total
          dgvTicketDetail.Columns(7).HeaderText = "Transport Total"
          dgvTicketDetail.Columns(7).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(7).DefaultCellStyle.NullValue = "0.00"
          dgvTicketDetail.Columns(7).ReadOnly = True
  
          'VAT Total
          dgvTicketDetail.Columns(8).HeaderText = "VAT Total"
          dgvTicketDetail.Columns(8).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(8).DefaultCellStyle.NullValue = "0.00"
          dgvTicketDetail.Columns(8).ReadOnly = True
  
          'line Total
          dgvTicketDetail.Columns(9).HeaderText = "Total"
          dgvTicketDetail.Columns(9).DefaultCellStyle.Format = "0.00"
          dgvTicketDetail.Columns(9).DefaultCellStyle.NullValue = "0.00"
          dgvTicketDetail.Columns(9).ReadOnly = True
  
  
          'line Total
          dgvTicketDetail.Columns(10).HeaderText = "TicketRef"
          dgvTicketDetail.Columns(10).Visible = False
      Finally
          If Con.State = ConnectionState.Open Then
              Con.Close()
          End If
      End Try
  
  End Sub
  </code></pre>
  
  <p>One of the columns is for the stock reference, at the minute i am able to free type this field, but ultimately i would like this to be a combobox column where the user can select from a list of stock references from another table.</p>
  
  <p>I have researched this issue and have found a number of examples which relate to creating a column at runtime but i dont feel that this would work in this situation as if i created the column manually then this would not be bound to the datasource which i want to save the information to.</p>
  
  <p>MANUAL COLUMN CREATION</p>
  
  <pre><code>Dim dgvc As DataGridViewComboBoxCell
  dgvc = DataGridView1.Rows(0).Cells(2)
  
  if DataGridView1.Rows(0).Cells(1).Value = "Jack" then
      dgvc.Items.Add("Fe")
      dgvc.Items.Add("Fi")
  elseif DataGridView1.Rows(0).Cells(3).Value = "Giant" then
      dgvc.Items.Add("Fo")
      dgvc.Items.Add("Fum")
  End if
  </code></pre>
  
  <p>I originally planned on manually adding the items to the combobox but i have seen examples of being able to databind the items. I suppose this is another issue for another time</p>
  
  <p>Any help is always appreciated.</p>
  
  <p>Thanks in advance guys</p>