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?


Thanks!
Eric BurtonSr.ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

            cbo.Items.Add(value)

            cboCol.Items.Add(value)


            grid.CurrentCell.Value = value
      End If

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.