Click here to Skip to main content
15,885,979 members
Articles / Programming Languages / Visual Basic

Embedding a DataGridView in a ComboBox

Rate me:
Please Sign up or sign in to vote.
4.95/5 (18 votes)
8 May 2013CPOL5 min read 68.4K   3.6K   61  
A simple way to place any DataGridView inside a ComboBox.
Partial Class AccGridComboBox

    ''' <summary>
    ''' Required designer variable.
    ''' </summary>
    Private components As System.ComponentModel.IContainer = Nothing

    ''' <summary>
    ''' Clean up any resources being used.
    ''' </summary>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If components IsNot Nothing Then components.Dispose()
            If DisposeToolStripDataGridView Then
                If Not myDropDown Is Nothing AndAlso Not myDropDown.IsDisposed Then myDropDown.Dispose()
                If Not myDataGridView Is Nothing AndAlso _
                    Not myDataGridView.DataGridViewControl Is Nothing AndAlso _
                    Not myDataGridView.DataGridViewControl.IsDisposed Then _
                    myDataGridView.DataGridViewControl.Dispose()
                If Not myDataGridView Is Nothing AndAlso Not myDataGridView.IsDisposed Then _
                    myDataGridView.Dispose()
            ElseIf Not DisposeToolStripDataGridView AndAlso Not myDropDown Is Nothing _
                 AndAlso Not myDropDown.IsDisposed Then
                If Not myDataGridView Is Nothing Then myDropDown.Items.Remove(myDataGridView)
                myDropDown.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

#Region "Component Designer generated code"

    ''' <summary>
    ''' Required method for Designer support - do not modify 
    ''' the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        Me.ResumeLayout(False)
    End Sub

#End Region
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Business Analyst Linden
Lithuania Lithuania
I'm a lawyer in a law firm. Programing is my hobby.

Comments and Discussions