5 Replies Latest reply on Jan 10, 2013 11:24 AM by John Seyler

    Visual Basic Problem

    Greg Johnson

      I have a combo box control inside a data grid view so I have to have code to be able to enter a custom value. But my code doesn't work, the code works fine if the user types in a custom value but doesn't work if it is one of the values from the combo box list. Here is a copy of my code that performs the task. In both cases the variable strValue contains the value that we are looking for but when the program exits from the sub the value is removed if it was selected from the list. Does anyone have any ideas on how to fix this?

       

          Private Sub dgdRevisions_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgdRevisions.CellValidating

              'These lines allow the user to type their own values into the datagridview comboboxes

              If e.ColumnIndex = colDescriptionLine1.DisplayIndex Then

                  Dim combobox As DataGridViewComboBoxCell = dgdRevisions(e.ColumnIndex, e.RowIndex)

                  'Store e.FormattedValue in Variable

                  Dim strValue As String = e.FormattedValue.ToString.ToUpper

                  'Clear text

                  dgdRevisions(e.ColumnIndex, e.RowIndex).Value = ""

                  'Clear existing Items in combobox

                  combobox.Items.Clear()

                  'Add default Items to combobox

                  PopulateStandardDescriptions(e.ColumnIndex, e.RowIndex)

                  'Add user value to combobox

                  If Not combobox.Items.Contains(strValue) Then

                      If Not strValue = "" Then

                          combobox.Items.Add(strValue)

                      End If

                  End If

                  dgdRevisions(e.ColumnIndex, e.RowIndex).Value = strValue

              End If

       

          End Sub