How to affect the way an extended control is instantiated

Posted on 2006-06-02
Last Modified: 2010-04-23
When the user instantiates my extended version of DataGridView I want it to have a certain number of rows and columns with various cell types. I know what to do just not where to put the code to do it.
Question by:tmostad
    1 Comment
    LVL 10

    Accepted Solution

    you can add an overload to the constructor (Sub New()) in the derived class

    Public MyClass
      Inherits Datagridview

      Public Sub New()
        InitializeMyGrid(5, 6)  ' Where 5 and 6 are the predefined grid size
      End Sub
      Public Sub New(Rows As Integer, Columns As Integer)
        InitializeMyGrid(Rows, Columns)
      End Sub

      Protected Sub InitializeMyGrid(Rows As Integer, Columns As Integer)
        ' Add the code to set the number of rows/columns
      End Sub
    End Class

    To instantiate
    ' To create a predefined gridsize
    Dim myPDgrid As New myClass()

    ' To create a customize gridzie
    Dim myCustGrid As New myClass(8,8)


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    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 …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    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…

    732 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

    23 Experts available now in Live!

    Get 1:1 Help Now