Combobox cell in DataGrid, Dropping down in one click instead of 2 – Possible?

I have a form that has a datagridview in it. I have bound this data with properties from a different class. The populating of the grid is working along with the populating from the dropdown is also working. The only question I have is it doesn’t matter what I do I always have to click twice to get the dropdown to dropdown. Is there anything I can do differently to get the cell to dropdown on the first click? Any help would be appreciated.

Private Property MountingPadDGVinfo As New BindingList(Of MountingPadInfoForDataGridView)

Private Sub BulkMountingPadEditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    ' Populate Type ComboBox column with Enum values
    Dim padTypeColumn As DataGridViewComboBoxColumn = CType(DataGridView_MountingPads.Columns("Type"), DataGridViewComboBoxColumn)
    padTypeColumn.Items.Clear()
    padTypeColumn.Items.AddRange([Enum].GetNames(GetType(MountingPadTypeEnum)))

    ' Populate Side ComboBox column with Enum values
    Dim padSideColumn As DataGridViewComboBoxColumn = CType(DataGridView_MountingPads.Columns("Side"), DataGridViewComboBoxColumn)
    padSideColumn.Items.Clear()
    padSideColumn.Items.AddRange([Enum].GetNames(GetType(MountingPadSideEnum)))

    ' Populate Pad1Angle ComboBox column with Double values
    Dim pad1AngleColumn As DataGridViewComboBoxColumn = CType(DataGridView_MountingPads.Columns("Pad1Angle"), DataGridViewComboBoxColumn)
    pad1AngleColumn.Items.Clear()
    pad1AngleColumn.Items.AddRange(g_DefaultMountingPadAngles.Cast(Of Object).ToArray()) ' Ensuring it's casted to Object to prevent mismatch

    ' Populate Pad2Angle ComboBox column with Double values
    Dim pad2AngleColumn As DataGridViewComboBoxColumn = CType(DataGridView_MountingPads.Columns("Pad2Angle"), DataGridViewComboBoxColumn)
    pad2AngleColumn.Items.Clear()
    pad2AngleColumn.Items.AddRange(g_DefaultMountingPadAngles.Cast(Of Object).ToArray())

    ' Populate PipeDia ComboBox column with Double values
    Dim pipeDiaColumn As DataGridViewComboBoxColumn = CType(DataGridView_MountingPads.Columns("PipeDia"), DataGridViewComboBoxColumn)
    pipeDiaColumn.Items.Clear()
    pipeDiaColumn.Items.AddRange(g_PipeDia.Cast(Of Object).ToArray())

    ' Set the DataGridView edit mode to enter edit mode when a cell is selected
    DataGridView_MountingPads.EditMode = DataGridViewEditMode.EditOnEnter


    ' Bind the DataGridView to the data source (BindingList)
    DataGridView_MountingPads.DataSource = MountingPadDGVinfo

End Sub

Private Sub HandleDataGridViewMouseDown(sender As Object, e As MouseEventArgs)
    ' Determine where the click is occurring
    Dim info As DataGridView.HitTestInfo = Me.DataGridView_MountingPads.HitTest(e.X, e.Y)

    ' Check if the click occurred in a cell
    If info.Type = DataGridViewHitTestType.Cell Then
        ' Set the clicked cell as the current cell
        Me.DataGridView_MountingPads.CurrentCell = Me.DataGridView_MountingPads.Rows(info.RowIndex).Cells(info.ColumnIndex)
    End If
End Sub

Private Sub DataGridView_MountingPads_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView_MountingPads.CellEnter
    ' Check if the entered cell belongs to a ComboBox column
    If e.ColumnIndex >= 0 AndAlso TypeOf DataGridView_MountingPads.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn Then
        ' Begin editing immediately on cell enter
        DataGridView_MountingPads.BeginEdit(True)

        ' Get the editing control (should be a ComboBox)
        Dim comboBox = TryCast(DataGridView_MountingPads.EditingControl, ComboBox)
        If comboBox IsNot Nothing Then
            ' Make sure ComboBox is focused and force dropdown
            comboBox.DroppedDown = False ' Reset the dropdown state
            comboBox.Focus()             ' Ensure ComboBox has focus
            comboBox.DroppedDown = True   ' Force dropdown to open
        End If
    End If
End Sub

Private Sub DataGridView_MountingPads_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView_MountingPads.CellLeave
    ' End editing when leaving the cell
    If e.ColumnIndex >= 0 AndAlso TypeOf DataGridView_MountingPads.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn Then
        DataGridView_MountingPads.EndEdit()
    End If
End Sub

Private Sub DataGridView_MountingPads_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView_MountingPads.EditingControlShowing
    ' Check if the control being shown is a ComboBox
    If TypeOf e.Control Is ComboBox Then
        Dim comboBox As ComboBox = DirectCast(e.Control, ComboBox)
        comboBox.DropDownStyle = ComboBoxStyle.DropDownList ' Ensure it acts like a dropdown
    End If
End Sub
Private Sub DataGridView_MountingPads_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView_MountingPads.DataError
    ' Suppress data errors
    e.ThrowException = False
End Sub

I have tried the above code and it is still requiring two clicks.

New contributor

Tiffany Hayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật