Question error in create a class inherits of DataGridViewColumnCollection

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
i create this class :

VB.NET:
Public Class MyDatagridviewColumnCollection
    Inherits DataGridViewColumnCollection
    Public Sub GetEquation()
        MsgBox("Get Equation here")
    End Sub
End Class

this error appear

VB.NET:
Error 1 Class 'WindowsApplication1.MyDatagridviewColumnCollection' must declare a 'Sub New' because its base class 'System.Windows.Forms.DataGridViewColumnCollection' does not have an accessible 'Sub New' that can be called with no arguments. C:\Users\pooyan\Documents\Visual Studio 2010\Projects\Test Projects\Datagridview Like Excel\Datagridview Like Excel\MyDatagridviewRow.vb 1 14 Datagridview Like Excel

what is its reason? please correct the wrong part....
 
It means that you have to add a constructor to your class or there is no way that an instance can be created. Just as you use the New keyword to create instances of other classes, so a DataGridView must use the New keyword to create instances of your class, which it can't do if you have not added any constructors to it.
 
If you can't find examples of how to declare a constructor then your web searching needs some serious work. Constructors are fairly fundamental to OOP so if you don't know what they are then you need to learn. Noone should be doing something like creating custom grid columns if they don't know basic things like how to declare a constructor. Learn to walk before trying to run. Look how easy it is to find information:

https://www.google.com.au/search?q=...s=org.mozilla:en-GB:official&client=firefox-a
 
Back
Top