• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

URGENT! VB.NET - Need to be able to type into a DataGridViewComboBoxColumn

Hello everyone,

I have a DataGridViewComboBoxColumn that is bound to a DataTable.  It works fine but I need to be able to type additional values into the the cell.  The values DO NOT have to be saved in the DataGridViewComboBox Items list, but they do have to be saved to the database.

How should I start?

Eric Burton
Eric Burton
1 Solution
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
hi.. this is best example for your solutions try this it's working

Private Sub GridStockItemEntry_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)

      Dim row As DataGridViewRow = GridStockItemEntry.CurrentRow
      Dim cell As DataGridViewCell = GridStockItemEntry.CurrentCell
      If e.Control.[GetType]() = GetType(DataGridViewComboBoxEditingControl) Then

            If cell = row.Cells("ItemName") AndAlso Convert.ToString(row.Cells("Type").Value) = "Raw Material" Then
                  Dim cbo As DataGridViewComboBoxEditingControl = TryCast(e.Control, DataGridViewComboBoxEditingControl)

                  cbo.DropDownStyle = ComboBoxStyle.DropDown

                  cbo.Validating += New CancelEventHandler(AddressOf cbo_Validating)
            End If
      End If

End Sub
Private Sub cbo_Validating(sender As Object, e As CancelEventArgs)

      Dim cbo As DataGridViewComboBoxEditingControl = TryCast(sender, DataGridViewComboBoxEditingControl)

      Dim grid As DataGridView = cbo.EditingControlDataGridView

      Dim value As Object = cbo.Text

      ' Add value to list if not there

      If cbo.Items.IndexOf(value) = -1 Then

            Dim cboCol As DataGridViewComboBoxCell = DirectCast(grid.CurrentCell, DataGridViewComboBoxCell)

            ' Must add to both the current combobox as well as the template, to avoid duplicate entries...



            grid.CurrentCell.Value = value
      End If

End Sub
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.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now