How do I integrate a user control with Visual Studio

Posted on 2005-04-15
Last Modified: 2008-03-03
I intend to write my own version of the Datagrid control that will display the rows using different colours for different rows, the colour for a row being dependent on the data the row contains.

My question is: once I have built this control, can I make it appear in Visual Studio's Toolbox? And if I drag an instance of my datagrid onto a new form will it look and behave like a normal datagrid? This is what I want to achieve.
Question by:kilgore666
    LVL 25

    Expert Comment

    yes, you can do it 2 ways. Just create a new usercontrol and replace the inherits part with something like, it will appear in the toolbox

    Public Class mydatagrid
        Inherits System.Windows.Forms.DataGrid

    #Region " Windows Form Designer generated code "

        Public Sub New()

            'This call is required by the Windows Form Designer.

            'Add any initialization after the InitializeComponent() call

        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                End If
            End If
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            components = New System.ComponentModel.Container()
        End Sub

    #End Region

    End Class

    or create a new class , that also inherits from datagrid compile it to a dll, and than just right click the toolbox and choose add remove items and browse to your dll
    LVL 32

    Accepted Solution

    Once you have built your control, you can add it to the Toolbox by right-clicking the Toolbox and selecting "Add/Remove Items."  Select your component and click "OK."  Your component should then be available in the Toolbox.

    Author Comment

    Thanks guys. I will split the points between you. But now I realise that there is something else I don't know which means I don't have a solution yet. See

    Author Comment

    Damn - I have forgotten how to split points - it was my intention to give you each 250.

    Ron, if you would like your 250 points then I am afraid you will have to remind me where I post the request to give you your points and what to say there.

    Sorry for the agro
    LVL 25

    Expert Comment

    Hi kilgote666,

    Don't worry about the points, I really don't care about them (It is not that I can buy anything with them :-)

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now