BigBoss
BigBoss

Reputation: 6914

How to inherit class in VB.NET

I'm pretty new to VB and I want to inherit from DataGridView, I use something like

Public Class DataGridViewEx Inherits DataGridView
End Class

But compiler generates an error as End of statement expected pointing to Inherits DataGridView. What is wrong and how I should do this?

Upvotes: 7

Views: 14667

Answers (2)

declared on the first line after the class, You can use Inherits only in a class or interface. This means the declaration context for an inheritance cannot be a source file, namespace, structure, module, procedure, or block.

https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/inherits-statement

Upvotes: -1

Tim Schmelter
Tim Schmelter

Reputation: 460098

Put it in the next line:

Public Class DataGridViewEx 
    Inherits DataGridView
End Class

MSDN: Inherits

If used, the Inherits statement must be the first non-blank, non-comment line in a class or interface definition. It should immediately follow the Class or Interface statement.

Upvotes: 14

Related Questions