datagrid and combobox....how to avoid error when edit control is NOT combobox?

The code attached ALMOST works, but when the edit control is a bound textbox on the same row, an error occurs...

Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxEditingControl' to type 'System.Windows.Forms.ComboBox'.

How do I avoid activating the code in EditingControlShowing when I don't need it or want it?

Thanks in advance.
Private Sub DataGridViewForms_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridViewForms.EditingControlShowing
        Dim editingComboBox As ComboBox = CType(e.Control, ComboBox)
        If Not editingComboBox Is Nothing Then
            AddHandler editingComboBox.SelectedIndexChanged, AddressOf editingComboBox_SelectedIndexChanged
        End If
    End Sub

    Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim comboBox1 As ComboBox = CType(sender, ComboBox)
        Dim dgr As System.Windows.Forms.DataGridViewRow = Nothing
        Dim fc As HPFFAFormClass = Nothing

        comboBox1.DisplayMember = "Description"
        comboBox1.ValueMember = "HPFDocType"

        dgr = Me.DataGridViewForms.CurrentRow
        fc = dgr.DataBoundItem
        fc.HPFDocType = comboBox1.SelectedValue
        Me.DataGridViewForms.Refresh()


    End Sub

Open in new window

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

cascader_grCommented:
Try this:


Dim editingComboBox As ComboBox 

If TypeOf (e.Control) Is ComboBox Then
    editingComboBox = DirectCast(e.Control, ComboBox)
Else
     Exit Sub
End If

Open in new window

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
codefingerAuthor Commented:
Tested...works like a charm...thanks!!
0
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.